我正在使用ionic 2 RC1并使用sublime作为文本编辑器。我需要检查网络连接是否连接。所以为此我使用离子原生Network来达到这个目的。但我面临的问题与可观察的Network.onDisconnect()
。我已编辑initializeApp()
方法,其中我检查网络连接并显示连接断开连接时的警报。在我写了下面的代码app.component.ts
IONIC 2 native Network.onDisconnect()运行代码两次
showAlert(title, msg) {
let alert = this.alertCtrl.create({
title: title,
subTitle: msg,
buttons: ['OK']
});
alert.present();
}
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
let disconnectSubscription = Network.onDisconnect().subscribe(() => {
this.showAlert("Error", "No internet connection");
});
StatusBar.styleDefault();
});
}
我面临的问题是,警报显示两次,如果应用程序从互联网断开。我在post中发现了类似的问题,但没有得到答复。任何有关这方面的帮助将不胜感激。 在此先感谢!
你能解决这个问题吗? – sebaferreras
不,我没有试图解决它,因为我已经转移到其他基于Web的项目。我认为这个问题应该已经在框架的新版本中解决了。 –