插件:
cordova plugin add cordova-plugin-networkinterface
编码:
networkinterface.getIpAddress((ip) => {
console.log(ip);
});
错误:
TypeError: Cannot read property 'getIPAddress' of undefined
这里我既没有提供任何提供者,也没有提供任何导入,那么它在离子2中是如何工作的呢?
这不是一个本机插件。但这个插件是工作在离子2也根据这个link
包. json:
{
"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);
});
}
2条答案
按热度按时间jxct1oxe1#
你必须使用它像下面安装后的非本机插件。
这个方法(
getIpAddress()
)已被取代,它使用getWiFiIPAddress()
方法。bq8i3lrv2#
您可以尝试使用外部URL:
无论在何处,都可以调用此函数: