无法在react-native

时间:2019-07-15 10:17:47

标签: firebase react-native push-notification react-native-android react-native-firebase

我正在使用react-native-firebase https://github.com/invertase/react-native-firebase将firebase推送通知集成到我的应用中。

我能够在所有情况下接收通知-i。前台应用程序; ii。后台或iii。应用处于终止状态,但是我无法在android中点击通知时启动我的应用。在iOS中,按预期的方式通过点击通知即可启动应用。

我已经通过以下链接:

https://github.com/rohitmodi12/firebasePushnotificaiton/issues/1

https://github.com/invertase/react-native-firebase-docs/blob/master/docs/notifications/receiving-notifications.md

https://github.com/rohitmodi12/firebasePushnotificaiton/blob/master/FirebaseNotifiction/App.js

以下是相关代码段:

      'channelId',
      'Channel Name',
      firebase.notifications.Android.Importance.Max
    ).setDescription('A natural description of the channel');
    firebase.notifications().android.createChannel(channel);
    // the listener returns a function you can use to unsubscribe
    this.unsubscribeFromNotificationListener = firebase.notifications().onNotification((notification) => {
      if (Platform.OS === 'android') {

        const localNotification = new firebase.notifications.Notification({
          sound: 'default',
          show_in_foreground: true,
        })
          .setNotificationId(notification.notificationId)
          .setTitle(notification.title)
          .setSubtitle(notification.subtitle)
          .setBody(notification.body)
          .setData(notification.data)
          .android.setChannelId('channelId') 
     .android.setPriority(firebase.notifications.Android.Priority.High)
        firebase.notifications()
          .displayNotification(localNotification)
          .catch(err => console.log(err));


      } else if (Platform.OS === 'ios') {

        const localNotification = new firebase.notifications.Notification()
          .setNotificationId(notification.notificationId)
          .setTitle(notification.title)
          .setSubtitle(notification.subtitle)
          .setBody(notification.body)
          .setData(notification.data)
          .ios.setBadge(notification.ios.badge);

        firebase.notifications()
          .displayNotification(localNotification)
          .catch(err => console.log(err));

      }
    });

在Manifiedt.xml中声明

<service android:name= "io.invertase.firebase.messaging.RNFirebaseMessagingService">
      <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter>
    </service>
    <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />


  <meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@mipmap/ic_launcher" />

  <meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/notificationColor" />

    <meta-data
      android:name="com.google.firebase.messaging.default_notification_channel_id"
      android:value="@string/default_notification_channel_id"/>

    <receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"/>
      <receiver android:enabled="true" android:exported="true"  android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver">
        <intent-filter>
          <action android:name="android.intent.action.BOOT_COMPLETED"/>
          <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
          <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
         <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
      </receiver>

Firebase配置

   apiKey: "AZzasaSy7876456456j4qrzSuU5q",
   authDomain: "xyz.firebaseapp.com",
   databaseURL: "https://xyz.firebaseio.com",
   projectId: "xyz",
   storageBucket: "xyz.appspot.com",
   messagingSenderId: "12321342142"
 };

 if (!firebase.apps.length) {
   firebase.initializeApp(config);
}

依赖项:

"dependencies": {
    "firebase": "^5.0.3",
    "lodash": "^4.17.11",
    "prop-types": "^15.6.2",
    "react": "16.4.1",
    "react-native": "0.56.0",
    "react-native-elements": "^0.19.1",
    "react-native-firebase": "^5.3.1",
    "react-native-iphone-x-helper": "^1.2.0",
    "react-native-keyboard-aware-scroll-view": "^0.8.0",
    "react-native-loading-spinner-overlay": "^1.0.1",
    "react-native-modal-datetime-picker": "^7.4.0",
    "react-native-navigation": "^2.3.0",
    "react-native-secure-key-store": "^2.0.2",
    "react-native-segmented-control-tab": "^3.3.1",
    "react-native-size-matters": "^0.2.1",
    "react-native-svg": "6.5.3",
    "react-native-svg-charts": "^5.2.0",
    "react-native-tabbar-bottom": "^1.0.4",
    "react-native-vector-icons": "^6.1.0",
    "react-redux": "^6.0.0",
    "redux": "^4.0.1"
  },

我在这里错过了什么吗?请提出建议。

0 个答案:

没有答案