0

我遇到了一些问题react-native-fcmreact-native-push-notification所以我决定尝试一下react-native-firebase

当应用程序处于前台时,我能够接收服务器发送的以下有效负载:

{
           "to":"FCM_TOKEN",
            "data": {
                "icon": "http://host.com/img.jpg",
                "title": "xyz title",
                "body": "sadsaddsasadsda",
                "click_action": "https://host.com/id/391",
                "data": "some json.stringify custom data"
            }

}

但是,当应用程序处于后台时,FCM.onMessage()根本不会收到任何通知。我可以在后台使用react-native-fcmor接收这些数据react-native-push-notification,所以我想知道这是否是react-native-firebase.

wixRoutes.js

import firebase from 'react-native-firebase';
import {Navigation} from 'react-native-navigation';

let FCM = firebase.messaging();

FCM.requestPermissions();

FCM.getToken().then(token=>{
    console.log('has token',token);
});

FCM.onTokenRefresh((refreshedToken) => {
    console.log(refreshedToken);
});

FCM.onMessage((message=>{
    console.log('new message',message);
}));

FCM.getInitialNotification().then(notif => {
    console.log('initial message',notif);
});


function startApp() {
   Navigation.startSingleScreenApp(/..../);
}

startApp();

AndroidManifest.xml

<!-- FCM -->
<service
        android:name="io.invertase.firebase.messaging.MessagingService"
        android:enabled="true"
        android:exported="true">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.InstanceIdService" android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
    </intent-filter>
</service>

<!-- If you would like to schedule local notifications then you also need to add the following:-->
<receiver android:name="io.invertase.firebase.messaging.RNFirebaseLocalMessagingPublisher"/>
<receiver android:enabled="true" android:exported="true" android:name="io.invertase.firebase.messaging.RNFirebaseSystemBootEventReceiver">
    <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>
<activity android:launchMode="singleTop" /......./ />
4

1 回答 1

0

原因是我的手机小米红 Note 4X 在开发者选项中默认设置了“不保留活动”这个选项,一旦应用程序进入后台就会终止应用程序,使其无法接收任何通知。Dsable 该选项,它工作正常。

于 2018-02-20T16:02:45.780 回答