From eb8f865a7c3570f7bb334b0682d33188efcccbe6 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Thu, 9 Jun 2016 13:49:37 -0400 Subject: [PATCH] pass token instead of object in refresh callback --- README.md | 14 ++++++-------- .../com/evollu/react/fcm/FIRMessagingModule.java | 13 +++++-------- ios/RNFIRMesssaging.m | 4 +--- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 024e317..8040636 100644 --- a/README.md +++ b/README.md @@ -89,15 +89,13 @@ in AppDelegate.m add - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { .... -[FIRApp configure]; <-- add this line + [FIRApp configure]; <-- add this line } //add this method -- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification { -[[NSNotificationCenter defaultCenter] postNotificationName: FCMNotificationReceived -object:self -userInfo:notification]; - +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler { + [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:notification]; + handler(UIBackgroundFetchResultNoData); } ``` @@ -120,8 +118,8 @@ In [firebase console](https://console.firebase.google.com/), you can get `google this.notificationUnsubscribe = FCM.on('notification', (notif) => { // there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload }); - this.refreshUnsubscribe = FCM.on('refresh', (data) => { - console.log(data.token) + this.refreshUnsubscribe = FCM.on('refreshToken', (token) => { + console.log(token) // fcm token may not be available on first load, catch it here }); } diff --git a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java index 96928ab..14536f2 100644 --- a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java +++ b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java @@ -93,15 +93,12 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li getReactApplicationContext().registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (getReactApplicationContext().hasActiveCatalystInstance()) { - String token = intent.getStringExtra("token"); - - WritableMap params = Arguments.createMap(); - params.putString("token", token); + if (getReactApplicationContext().hasActiveCatalystInstance()) { + String token = intent.getStringExtra("token"); - sendEvent("FCMTokenRefreshed", params); - abortBroadcast(); - } + sendEvent("FCMTokenRefreshed", token); + abortBroadcast(); + } } }, intentFilter); } diff --git a/ios/RNFIRMesssaging.m b/ios/RNFIRMesssaging.m index 98bf37e..f12b5b5 100644 --- a/ios/RNFIRMesssaging.m +++ b/ios/RNFIRMesssaging.m @@ -86,9 +86,7 @@ RCT_REMAP_METHOD(getFCMToken, - (void) onTokenRefresh { - NSDictionary *info = @{@"token":[[FIRInstanceID instanceID] token]}; - [_bridge.eventDispatcher sendDeviceEventWithName:@"FCMTokenRefreshed" - body:info]; + [_bridge.eventDispatcher sendDeviceEventWithName:@"FCMTokenRefreshed" body:[[FIRInstanceID instanceID] token]]; } RCT_EXPORT_METHOD(requestPermissions) -- 2.26.2