2017-04-09 9 views
2

플러그인 :GET 라우터의 IP 주소 - 비 네이티브 플러그인

cordova plugin add cordova-plugin-networkinterface 

코드 :

networkinterface.getIpAddress((ip) => { 
    console.log(ip); 
}); 

오류 :

TypeError: Cannot read property 'getIPAddress' of undefined 
현재 이곳에

둘 다 내가 어떤 업체에 제공이없는 도 아니다 수입품, 그래서 그것은 어떻게 wor? 이온 2의 k?
네이티브 플러그인이 아닙니다. 하지만이 플러그인은이 link

Package.json에 따라 이온 2에서 일하고 :

{ 
    "name": "ionic-hello-world", 
    "author": "Ionic Framework", 
    "homepage": "http://ionicframework.com/", 
    "private": true, 
    "scripts": { 
    "clean": "ionic-app-scripts clean", 
    "build": "ionic-app-scripts build", 
    "ionic:build": "ionic-app-scripts build", 
    "ionic:serve": "ionic-app-scripts serve" 
}, 
"dependencies": { 
"@angular/common": "2.4.8", 
"@angular/compiler": "2.4.8", 
"@angular/compiler-cli": "2.4.8", 
"@angular/core": "2.4.8", 
"@angular/forms": "2.4.8", 
"@angular/http": "2.4.8", 
"@angular/platform-browser": "2.4.8", 
"@angular/platform-browser-dynamic": "2.4.8", 
"@angular/platform-server": "2.4.8", 
"@ionic-native/core": "3.1.0", 
"@ionic-native/in-app-browser": "^3.4.2", 
"@ionic-native/network": "^3.4.2", 
"@ionic-native/splash-screen": "3.1.0", 
"@ionic-native/status-bar": "3.1.0", 
"@ionic-native/toast": "^3.4.4", 
"@ionic/app-scripts": "^1.2.2", 
"@ionic/storage": "2.0.0", 
"ionic-angular": "2.3.0", 
"ionic-native": "^2.9.0", 
"ionicons": "3.0.0", 
"rxjs": "5.0.1", 
"sw-toolbox": "3.4.0", 
"zone.js": "0.7.2" 
}, 
"devDependencies": { 
    "@ionic/app-scripts": "1.2.2", 
    "typescript": "2.0.9" 
}, 
"cordovaPlugins": [ 
"cordova-plugin-whitelist", 
"cordova-plugin-statusbar", 
"cordova-plugin-console", 
"cordova-plugin-device", 
"cordova-plugin-splashscreen", 
"ionic-plugin-keyboard" 
    ], 
    "cordovaPlatforms": [], 
    "description": "Test" 
} 

최신 코드 파일 : 당신은 비를 설치 한 후 아래처럼 사용할 필요가

declare var networkinterface: any; 

    @Component({ 
    templateUrl: 'app.html' 
    }) 
    export class MyApp { 
    public rootPage:any = HomePage; 

    constructor(private platform: Platform,private statusBar: StatusBar,private splashScreen: SplashScreen, private network: Network, private iab: InAppBrowser, private http: Http, private toast: Toast) { 

    platform.ready().then(() => { 
     networkinterface.getWiFiIPAddress((ip) => { 
       console.log(ip); 
    }); 
} 
+0

당신은 당신의'package.json'를 게재 할 수 있습니까? – Sampath

+0

네이티브 플러그인을 사용하고 있습니까? 그것의 URL? – Sampath

+0

네이티브 플러그인이 아닙니다. [link] (https://github.com/salbahra/cordova-plugin-networkinterface) –

답변

0

- 네이티브 플러그인.

This method (getIpAddress()) is deprecated and uses the getWiFiIPAddress() method.

 declare let networkinterface: any; 

     @Component({ 
      ... 
     }) 
     export class TestPage { 

      ... 

      getIpAddress() { 
      networkinterface.getWiFiIPAddress((ip) => { 
      console.log(ip); 
     }); 
     } 
    } 
+0

error_handler.js : 54 예외 : 알려지지 않은 약속 있음 : ReferenceError : networkinterface가 정의되지 않았습니다. ReferenceError : networkinterface가 정의되지 않았습니다. –

+0

위의 게시물에 최신 코드를 넣을 수 있습니까? – Sampath

+0

'var' 대신'let'을 사용하십시오. – Sampath