mapp-digital / Mapp-Engage-ReactNative-Plugin

0 stars 1 forks source link

Notification function conflict for firebase and Mapp #5

Open Maharshi01 opened 3 years ago

Maharshi01 commented 3 years ago

Please find the firebase functions that we are using for notification listening :

// To listen to messages in the foreground, call the onMessage this.removeMessageListener = messaging().onMessage(async notification => { try { NavigationService.getNavigator().props.screenProps.globalEvents.emit('notification', true); LogTracker.debug("Messaging Service - FCM: onMessage", notification); } catch (error) { LogTracker.debug("Messaging Service - FCM: onMessage Error", error); }

    });

    //When the application is in a background or quit state, the onMessage handler will not be called when receiving messages. 
    //Instead, you need to setup a background callback handler via the setBackgroundMessageHandler method
    this.removeNotificationListener = messaging().setBackgroundMessageHandler(async notification => {
        try {
            LogTracker.debug("Messaging Service - FCM: setBackgroundMessageHandler", notification);
        } catch (error) {
            LogTracker.debug("Messaging Service - FCM: setBackgroundMessageHandler Error", error);
        }
    });

    //When the application is opened from a quit state.(When user click the notification)
    messaging().getInitialNotification().then((notificationOpen) => {
        try {
            LogTracker.debug("Messaging Service - FCM: getInitialNotification", notificationOpen);
            if (notificationOpen) {
                const { title, body, notificationId, subTitle, data } = notificationOpen;
                let targetValue = JSON.parse(data.navigateTo)
                TargetHandler.navigateTarget(targetValue)
            }
        } catch (error) {
            LogTracker.debug("Messaging Service - FCM: getInitialNotification Error", error);
        }

    });

    //When the application is running, but in the background.(When user click the notification)
    this.removeNotificationOpenedListener = messaging().onNotificationOpenedApp((notificationOpen) => {
        try {
            LogTracker.debug("Messaging Service - FCM: onNotificationOpened", notificationOpen);
            const { title, body, notificationId, subTitle, data } = notificationOpen;
            let targetValue = JSON.parse(data.navigateTo)
            TargetHandler.navigateTarget(targetValue)
        } catch (error) {
            LogTracker.debug("Messaging Service - FCM: onNotificationOpened Error", error);
        }

    });
acamarinkovic commented 3 years ago

Hi, @Maharshi01 We have 2 options for this issue. The first one is in this class to extend our service (We must change it in modules or fork project and republish it...)https://github.com/invertase/react-native-firebase/blob/master/packages/messaging/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingService.java ...

The second one is I can emit all these events from our SDK but only in case if you use Firebase only for android or you can remove the RN Firebase part for android and keep it for iOS .

There is also the possibility to make functions that forward PushMessage and Token from Firebase RN SDK to OUR but it will take much more time

What do you think? Is this first option ok for you?

Maharshi01 commented 3 years ago

Hi @acamarinkovic

I think the first option looks okay to me 'cause we cannot go with second approach as UMobile application uses firebase services for both android and ios

acamarinkovic commented 3 years ago

Hi @Maharshi01,

I'm fork project and make changes to what you should do on your module https://github.com/acamarinkovic/react-native-firebase/commit/c533db11101e1ab40132e6a29f26137f3e08e53b .

I don't know if it will have any side effects on your application. If it is, we will adjust the solution.

Maharshi01 commented 3 years ago

Okay @acamarinkovic , Did you merge it and publish it ? I hope that there shouldn't be any : )