diff --git a/README.md b/README.md index 024e31722e8c5f579b806ae80504b048238d1974..8040636bc092c9f5dc6a205aba673f756a0f0e03 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 96928ab92927afb4aeefe1358b30bd9fc54a0479..14536f21e7bcb516ca3cdb3c82b981d8405f0589 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 98bf37e7016532f08e5d88440e14123d52d59e2a..f12b5b57e99ce872a8c7466a2ec8fb66fecd6f2a 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)