Gerencie múltiplos provedores de push em aplicações móveis
Se você tem múltiplos provedores push no seu aplicativo móvel, precisa alterar levemente a integração para remover instâncias duplicadas de classes de dependência e para lidar adequadamente com as mensagens recebidas.
Android
Este guia é para aplicativos Android que usam a versão 7.2.0 e superiores do Xtremepush SDK.
Adicione o seguinte ao seu arquivo manifest para remover a entrada da classe filha Xtremepush FirebaseMessageingService . Isso evitará qualquer conflito potencial entre os dois provedores de push.
<service
android:name="ie.imobile.extremepush.google.XPFirebaseMessagingService"
tools:node="remove">
</service>Agora, dentro da sua própria classe filho FirebaseMessagingService, você precisará atualizar a onMessageReceived função para que ela trate as mensagens recebidas da seguinte forma:
@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
}
}Na mesma turma, você também precisará atualizar a onNewToken função, da seguinte forma:
@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
se você precisar verificar se uma mensagem veio do Xtremepush, para poder ignorá-la, pode fazer o seguinte:
- (void)application:(UIApplication )application didReceiveRemoteNotification:(NSDictionary )userInfo {
if ([userInfo objectForKey:@"xpush"] != nil) {
[XPush applicationDidReceiveRemoteNotification:userInfo fetchCompletionHandler:nil];
}
// Do you our own thing if needed
}
// Called when a notification is received while the app is in the foreground
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
NSDictionary *userInfo = notification.request.content.userInfo;
if (userInfo[@"xpush"] != nil) {
// Forward XPush notifications to the SDK
[XPush userNotificationCenter:center
willPresentNotification:notification
withCompletionHandler:completionHandler];
return; // SDK calls completionHandler
}
// Handle non-XPush notifications here (if applicable)
completionHandler(UNNotificationPresentationOptionAlert);
}
// Called when the user taps a notification or interacts with an action button
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
if (userInfo[@"xpush"] != nil) {
// Forward XPush notifications to the SDK
[XPush userNotificationCenter:center
didReceiveNotificationResponse:response
withCompletionHandler:completionHandler];
return; // SDK calls completionHandler
}
// Handle non-XPush notification actions here (if applicable)
completionHandler();
}
// Called when the user taps a notification or interacts with an action button
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
if (userInfo[@"xpush"] != nil) {
// Forward XPush notifications to the SDK
[XPush userNotificationCenter:center
didReceiveNotificationResponse:response
withCompletionHandler:completionHandler];
return; // SDK calls completionHandler
}
// Handle non-XPush notification actions here (if applicable)
completionHandler();
}func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
if userInfo["xpush"] != nil {
XPush.applicationDidReceiveRemoteNotification(userInfo, fetchCompletionHandler: nil)
}
// Do you our own thing if needed
}
// Called when a notification is received while the app is in the foreground
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
NSDictionary *userInfo = notification.request.content.userInfo;
if (userInfo[@"xpush"] != nil) {
// Forward XPush notifications to the SDK
[XPush userNotificationCenter:center
willPresentNotification:notification
withCompletionHandler:completionHandler];
return; // SDK calls completionHandler
}
// Handle non-XPush notifications here (if applicable)
completionHandler(UNNotificationPresentationOptionAlert);
}
// Called when the user taps a notification or interacts with an action button
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
if (userInfo[@"xpush"] != nil) {
// Forward XPush notifications to the SDK
[XPush userNotificationCenter:center
didReceiveNotificationResponse:response
withCompletionHandler:completionHandler];
return; // SDK calls completionHandler
}
// Handle non-XPush notification actions here (if applicable)
completionHandler();
}Se estiver usando o plugin Xtremepush Phonegap para iOS, por favor, siga o adicional Phonegap Multiple Push Providers iOS