Безголовая задача убивает себя, когда приложение убито - PullRequest
0 голосов
/ 01 июля 2018

Мой сервис убивает себя, когда приложение убивается / закрывается.

Вот фоновый сервис, который я реализую (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);

Согласно документации response-native-firebase , эта реализация должна работать. Однако служба RNFirebaseBackgroundMessage убивает себя, когда приложение убивается / закрывается.

Это связано с реализацией react-native-navigation? Это точный пример моей реализации реакции-нативной навигации.

Использование response-native@0.53.3 и response@16.2.0

Пожалуйста, помогите.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...