1

アプリケーションが開いているときとバックグラウンドになっているときだけ、私のアプリケーションが通知を受け取っていました。しかし、私はアプリが閉じても到達する必要があります通知が必要です。どのように私は反応ネイティブfcmを使用して反応系でこれを行うことができますか?React-native-fcmは閉鎖したアプリケーションの通知をプッシュしません

私のコードは、あなたの問題は、あなたの通知を推進している方法です下のそれを参照してください

FCM.getInitialNotification().then(notif=>console.log(notif)); 
      FCM.requestPermissions(); // for iOS 
      FCM.getFCMToken().then(token => { 
       console.log(token) 
       // store fcm token in your server 
      }); 
      this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => { 
       // there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload 
       if(notif.local_notification){ 
        //this is a local notification 
        return; 
       } 
       if(notif.opened_from_tray){ 
        //app is open/resumed because user clicked banner 
        console.log('clicked'); 

        return; 
       } 
       this.showLocalNotification(notif); 

      }); 
      this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, (token) => { 
       console.log(token) 
       // fcm token may not be available on first load, catch it here 
      }); 

     showLocalNotification(notif) { 
      FCM.presentLocalNotification({ 
      title: notif.title, 
      body: notif.body, 
      priority: "high", 
      click_action: notif.click_action, 
      show_in_foreground: true, 
      local: true 
      }); 
     } 

<uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.VIBRATE"/> 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 

    <uses-sdk 
     android:minSdkVersion="16" 
     android:targetSdkVersion="22" /> 

    <application 
     android:name=".MainApplication" 
     android:allowBackup="true" 
     android:label="@string/app_name" 
     android:icon="@mipmap/ic_launcher" 
     android:theme="@style/AppTheme"> 

     <receiver android:name="com.evollu.react.fcm.FIRLocalMessagingPublisher"/> 
     <receiver android:enabled="true" android:exported="true" android:name="com.evollu.react.fcm.FIRSystemBootEventReceiver"> 
     <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> 

     <service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true"> 
     <intent-filter> 
      <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
     </intent-filter> 
     </service> 

     <service android:name="com.evollu.react.fcm.InstanceIdService" android:exported="false"> 
     <intent-filter> 
      <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 
     </intent-filter> 
     </service> 

     <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenSize" 
     android:windowSoftInputMode="adjustResize"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="fcm.ACTION.HELLO" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
     </activity> 
     <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" /> 
     <meta-data 
     android:name="com.google.android.geo.API_KEY" 
     android:value="XXXXXX"/> 
    </application> 
+0

'data'- * only *ペイロードメッセージの使用を検討しましたか? –

+0

私はデータと通知の両方を送信しています。私はこれに新しいです。私はちょうど私のrequirmentのための反応ネイティブfcmを使用しています。 –

+0

申し訳ありません。私は混乱した。アプリがフォアグラウンド/バックグラウンドのときに自分でメッセージを処理することを好みました。 Androidの動作では、 'data'と' notification'の両方でペイロードを送信すると、通知トレイがペイロードを処理します。あなたは通知を一切見ないのですか?複数のデバイスでこれをテストしましたか? –

答えて

3

ました。 FCMは、属性「通知」を含む通知のみを認識してポップアップします。

次のコマンド

this.showLocalNotification(NOTIF)を必要とする場合、

あなたの通知を表示するには、ローカルで通知を管理していることを意味します。したがって、閉じたアプリケーションは管理しません。

その結果、通知をクラウドに送信する方法を確認し、「通知」属性を持たない場合にのみイベント「FCMEvent.Notification」がトリガーされるようにしてください。

例:

noteA = {notification: {title: "Notification Title", body:"Notification body"}, data: {optional: "content"}}; 
noteB = {title: "Notification Title", body:"Notification body"}, data: {optional: "content"}}; 

結果:

noteA:FCMEvent.Notification

noteBをトリガすることなく、通知をポップアップする必要があります。FCMEvent.Notificationをトリガーとthis.showLocalNotification(NOTIF)がある場合にすべき呼び出されたローカル通知が表示されます。

関連する問題