Firebase 爱奥尼亚3-收到通知后打开应用程序

Firebase 爱奥尼亚3-收到通知后打开应用程序,firebase,ionic-framework,android-intent,notifications,Firebase,Ionic Framework,Android Intent,Notifications,我的应用程序的通知工作正常,使用在后台和前台接收通知。现在,我的客户端需要在收到通知时打开应用程序,而无需任何用户迭代 我发现是的,但没有正确的答案 在调试时,我意识到通知是通过广播接收的。所以,我试过: 修改 plugins/cordova plugin firebase lib/plugin.xml 这是一次编译,但什么也没发生 修改config.xml并使用替换firebase lib的config.xml并与我的合并,调用正确的意图。 此文件无法编译,并出现以下错误: 我的问题是:最好的

我的应用程序的通知工作正常,使用在后台和前台接收通知。现在,我的客户端需要在收到通知时打开应用程序,而无需任何用户迭代

我发现是的,但没有正确的答案

在调试时,我意识到通知是通过广播接收的。所以,我试过:

修改 plugins/cordova plugin firebase lib/plugin.xml

这是一次编译,但什么也没发生

修改config.xml并使用替换firebase lib的config.xml并与我的合并,调用正确的意图。 此文件无法编译,并出现以下错误:

我的问题是:最好的归档方法是什么?有人能给我举个真实的例子吗


谢谢你抽出时间

如果有人需要,我的解决方案就是使用插件

这个问题的解决方法其实很简单。不需要意图,只需安装'@ionic native/background mode'

对于Ionic 3,使用以下命令安装插件:

ionic cordova plugin add cordova-plugin-background-mode
npm install --save @ionic-native/background-mode@4
文件:app.module.ts:

加载项提供程序:

providers: [
    BackgroundMode,
    ...
  ],
文件:app.component.ts:

导入后台模式插件:

import {BackgroundMode} from "@ionic-native/background-mode";
附加构造函数

constructor(
        platform: Platform, 
        statusBar: StatusBar, 
        splashScreen: SplashScreen,         
        ...
        private backgroundMode: BackgroundMode) {

        this.backgroundMode.enable();
        this.backgroundMode.excludeFromTaskList();
        this.backgroundMode.overrideBackButton();
        // this.backgroundMode.setDefaults({silent: true});

        this.backgroundMode.on('activate').subscribe(value => {
            this.backgroundMode.disableWebViewOptimizations();
        });
}
文件:fcm.ts

这里是所有Firebase通知的位置。首先,导入背景模式:

import {BackgroundMode} from "@ionic-native/background-mode";
现在,我们只需在onNotificationOpen上调用这两个函数,这是firebase在通知到达时调用的函数:

listenToNotifications() {
    return this.firebaseNative.onNotificationOpen()
  }

this.listenToNotifications().subscribe(
      ((msg: any) => {

          // 'These two functions make the magic'

          this.backgroundMode.unlock();
          this.backgroundMode.moveToForeground();

          if (!msg.tap)
            this.events.publish(this.dataInfo.eventFcmNew, msg)        
          else 
              this.events.publish('push', 'NotificationsPage')                  
      })
  )
就这样


您提供的潜在解决方案链接包含实现此目的的所有相关信息。如前所述,除了高度侵入性和不受欢迎之外,根本不能保证它能与新版本的android一起工作。此外,这是非常具体的功能,没有cordova插件能够实现这一点。您需要编写自己的本机代码。谢谢您的评论。在接收到的Firebase广播中,仅仅使用意图打开应用程序是不可能的?我只需要在通知到达时打开应用程序,就像Skype一样。我已经在其他Android应用程序上看到了这一功能。不可能只使用意图在接收到的Firebase广播中打开应用程序?–虽然技术上是正确的,但我们在这里混合了苹果和橙子。在config.xml中定义的意图过滤器与从服务启动活动所需创建的实际意图几乎没有关系。你的答案在这里:。该插件不支持它,您需要用Java编写自己的实现。。。谢谢你给我一个方向,也许如果你用电容器做服务,听听firebase的override onMessageSerecive。你可以打开你的应用程序。您还可以制作broascast listiner,以便在应用程序即将关闭时保持servicre的活动状态。
listenToNotifications() {
    return this.firebaseNative.onNotificationOpen()
  }

this.listenToNotifications().subscribe(
      ((msg: any) => {

          // 'These two functions make the magic'

          this.backgroundMode.unlock();
          this.backgroundMode.moveToForeground();

          if (!msg.tap)
            this.events.publish(this.dataInfo.eventFcmNew, msg)        
          else 
              this.events.publish('push', 'NotificationsPage')                  
      })
  )