应用被终止/关闭时,我的服务也会终止。
这是我正在实施的后台服务(bgMessaging.js
):
import firebase from 'react-native-firebase';
// Optional flow type
import type { RemoteMessage } from 'react-native-firebase';
export default async (message: RemoteMessage) => {
// handle your message
console.log("RemoteMessage", message);
const newNotification = new firebase.notifications.Notification()
.android.setSmallIcon(message.data.icon)
.android.setChannelId(message.data.channel_id)
.android.setAutoCancel(true)
.android.setBigText(message.data.body)
.setNotificationId(message.messageId)
.setBody(message.data.body);
if(message.data.title != undefined)
newNotification.setTitle(message.data.title);
if(message.data.color != undefined)
newNotification.android.setColor(message.data.color);
if(message.data.bigPicture != undefined)
newNotification.android.setBigPicture(message.data.bigPicture);
if(message.data.largeIcon != undefined)
newNotification.android.setLargeIcon(message.data.largeIcon);
firebase.notifications().displayNotification(newNotification);
return Promise.resolve();
}
这是我的index.js
:
import { AppRegistry } from 'react-native';
import App from './app';
import bgMessaging from './bgMessaging';
const app = new App();
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessaging);
根据react-native-firebase的文档,此实现应起作用。但是,RNFirebaseBackgroundMessage
服务会在应用程序被终止/关闭时自动终止。
这是由于react-native-navigation
的实现吗?这与我对react-native-navigation的实现完全一样example。
使用react-native@0.53.3和react@16.2.0
请帮助。