最近,我一直在我的应用程序中添加推送通知功能。我正在使用在此 link 上找到的 FCN 插件我使用 Ionic 2 框架进行开发。通知已发送,但当我点击它时,它只会打开应用程序的主页,而不是我需要的内页。
我用过这段代码
declare var FCMPlugin;
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;
horoscopePage:any = HoroscopeHomePage;
@ViewChild(Nav) nav: Nav;
**********************
FCMPlugin.onNotification(function(data){
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
if(data.topic =="horoskopi" && data.type=="list"){
console.log( JSON.stringify(data) );
this.nav.push(this.horoscopePage);
}
}else{
if(data.topic =="horoskopi" && data.type=="list"){
console.log( JSON.stringify(data) );
this.nav.push(this.horoscopePage);
}
}
});
});
这行代码 this.nav.push(this.horoscopePage);
没有做任何事情
当我改用 NavController 时,它给我这个错误:
MyApp_Host.html:1 ERROR Error: No provider for NavController!
at injectionError (core.es5.js:1231)
at noProviderError (core.es5.js:1269)
at ReflectiveInjector_._throwOrNull (core.es5.js:2770)
at ReflectiveInjector_._getByKeyDefault (core.es5.js:2809)
at ReflectiveInjector_._getByKey (core.es5.js:2741)
at ReflectiveInjector_.get (core.es5.js:2610)
at AppModuleInjector.NgModuleInjector.get (core.es5.js:3578)
at resolveDep (core.es5.js:11039)
at createClass (core.es5.js:10903)
at createDirectiveInstance (core.es5.js:10723)
最佳答案
您可以将 public navCtrl: NavController
添加到 constructor
中,然后将代码更改为
this.navCtrl.push(this.horoscopePage);
关于ios - 点击推送通知后打开一个页面 Ionic 2 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46201098/