ios - 点击推送通知后打开一个页面 Ionic 2 iOS

标签 ios cordova ionic2 cordova-plugin-fcm

最近,我一直在我的应用程序中添加推送通知功能。我正在使用在此 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/

相关文章:

ios - 从 nib 初始化自定义 UITableViewCell,无需 dequeueReusableCellWithIdentifier

ios - 如何将 addTarget 方法更新为 swift 4

iphone - 如何使用 PhoneGap 创建选项卡栏

visual-studio - Visual Studio 2015 在保存时删除文件 - cordova 解决方案

android - Worklight 应用程序崩溃并出现错误 android.content.res.Resources$NotFoundException

angular - 如何禁用angular 2中的div标签

ios - 通过代码添加 UIView 时出现重叠问题

ios - 解析.com : Searching a TableView

google-maps - ionic 2/3 : Is it possible to open google map APP by passing custom lat- long?

angular - 我如何跟踪 ionic 2 中 app.component.ts 中的每个错误