Commit eb8f865a authored by Libin Lu's avatar Libin Lu

pass token instead of object in refresh callback

parent fd8f4a4c
...@@ -89,15 +89,13 @@ in AppDelegate.m add ...@@ -89,15 +89,13 @@ in AppDelegate.m add
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ {
.... ....
[FIRApp configure]; <-- add this line [FIRApp configure]; <-- add this line
} }
//add this method //add this method
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification { - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {
[[NSNotificationCenter defaultCenter] postNotificationName: FCMNotificationReceived [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:notification];
object:self handler(UIBackgroundFetchResultNoData);
userInfo:notification];
} }
``` ```
...@@ -120,8 +118,8 @@ In [firebase console](https://console.firebase.google.com/), you can get `google ...@@ -120,8 +118,8 @@ In [firebase console](https://console.firebase.google.com/), you can get `google
this.notificationUnsubscribe = FCM.on('notification', (notif) => { this.notificationUnsubscribe = FCM.on('notification', (notif) => {
// there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload // there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
}); });
this.refreshUnsubscribe = FCM.on('refresh', (data) => { this.refreshUnsubscribe = FCM.on('refreshToken', (token) => {
console.log(data.token) console.log(token)
// fcm token may not be available on first load, catch it here // fcm token may not be available on first load, catch it here
}); });
} }
......
...@@ -96,10 +96,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -96,10 +96,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
if (getReactApplicationContext().hasActiveCatalystInstance()) { if (getReactApplicationContext().hasActiveCatalystInstance()) {
String token = intent.getStringExtra("token"); String token = intent.getStringExtra("token");
WritableMap params = Arguments.createMap(); sendEvent("FCMTokenRefreshed", token);
params.putString("token", token);
sendEvent("FCMTokenRefreshed", params);
abortBroadcast(); abortBroadcast();
} }
} }
......
...@@ -86,9 +86,7 @@ RCT_REMAP_METHOD(getFCMToken, ...@@ -86,9 +86,7 @@ RCT_REMAP_METHOD(getFCMToken,
- (void) onTokenRefresh - (void) onTokenRefresh
{ {
NSDictionary *info = @{@"token":[[FIRInstanceID instanceID] token]}; [_bridge.eventDispatcher sendDeviceEventWithName:@"FCMTokenRefreshed" body:[[FIRInstanceID instanceID] token]];
[_bridge.eventDispatcher sendDeviceEventWithName:@"FCMTokenRefreshed"
body:info];
} }
RCT_EXPORT_METHOD(requestPermissions) RCT_EXPORT_METHOD(requestPermissions)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment