Multiple push providers

Handle multiple push providers in mobile applications

If you have multiple push providers in your mobile application, you have to slightly alter the integration to remove duplicate instances of dependency classes, and to appropriately handle incoming messages.

Android

This guide is for Android apps using version 7.2.0 and greater of the Xtremepush SDK.

Add the following to your manifest file to remove the Xtremepush FirebaseMessageingService child class entry. This will prevent any potential conflict between the two push providers.

<service
    android:name="ie.imobile.extremepush.google.XPFirebaseMessagingService"
    tools:node="remove">
</service>

Now, inside your own FirebaseMessagingService child class you will need to update the onMessageReceived function so that it handles incoming messages as follows:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    //Check if message is xpush message
    if (PushConnector.isXpushMessage(this, remoteMessage)) {
        //if xpush message, pass to xpush to manage
        PushConnector.fcmShareRemoteMessage(this, remoteMessage);
    } else {
        //handle non xpush message
    }

}

In the same class, you will also need to update the onNewToken function, as follows:

@Override
public void onNewToken(String token) {
    //share the token with XPush so it is available to both providers
    PushConnector.fcmShareToken(this, token);
    //non xpush use of token
}

iOS

if you need to check if a message has come from Xtremepush, so you can ignore it, you could do the following:

func application(_ application: UIApplication,
                     didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
    if userInfo["xpush"] != nil {
        XPush.applicationDidReceiveRemoteNotification(userInfo, fetchCompletionHandler: nil)
    }
    // Do you our own thing if needed    
}
- (void)application:(UIApplication )application didReceiveRemoteNotification:(NSDictionary )userInfo {
    if ([userInfo objectForKey:@"xpush"] != nil) {
        [XPush applicationDidReceiveRemoteNotification:userInfo fetchCompletionHandler:nil];
    }
    // Do you our own thing if needed
}

If using the Xtremepush Phonegap plugin for iOS please follow the additional Phonegap Multiple Push Providers iOS