diff --git a/CHANGELOG.md b/CHANGELOG.md index d7ba15c38104537b47b8c109e4f61f5cff1f6747..c0cf7680a8988d3d3942d0af06a8eb0b5bb0ced7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -### 1.0.12 +### 1.0.12 BREAKING CHANGES - get initial intent inside module, support rn 0.29.0 (for people upgrading from older version, change `new FIRMessagingPackage(getIntent())` back to `new FIRMessagingPackage()`) +- remove initAction as it is just duplication of initData ### 1.0.11 - change android library version to use 9.+ instead of 9.0.1 so it lives well with other libraries 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 d13cfb8e2b0f863925ae877284efb62905b10e4c..0a926e99c4d6f9aaf04604ec1053fd491b27963e 100644 --- a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java +++ b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java @@ -27,13 +27,10 @@ import java.util.Set; public class FIRMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener { private final static String TAG = FIRMessagingModule.class.getCanonicalName(); - Intent mIntent; + Intent currentIntent; public FIRMessagingModule(ReactApplicationContext reactContext) { super(reactContext); - - mIntent = getCurrentActivity().getIntent(); - getReactApplicationContext().addLifecycleEventListener(this); registerTokenRefreshHandler(); registerMessageHandler(); @@ -42,18 +39,6 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li @Override public Map getConstants() { Map constants = new HashMap<>(); - if (mIntent != null) { - if(mIntent.getExtras() != null) { - Map extra = new HashMap<>(); - Bundle data = mIntent.getExtras(); - Set keysIterator = data.keySet(); - for(String key: keysIterator){ - extra.put(key, data.get(key)); - } - constants.put("initialData", extra); - } - constants.put("initialAction", mIntent.getAction()); - } return constants; } @@ -130,17 +115,26 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li @Override public void onHostResume() { Intent newIntent = getCurrentActivity().getIntent(); - if(newIntent != mIntent && newIntent != null){ - Bundle extras = newIntent.getExtras(); - if (extras != null) { - WritableMap params = Arguments.fromBundle(extras); - WritableMap fcm = Arguments.createMap(); - fcm.putString("action", newIntent.getAction()); - params.putMap("fcm", fcm); - sendEvent("FCMNotificationReceived", params); - } + if(newIntent == currentIntent){ + return; + } + WritableMap params; + Bundle extras = newIntent.getExtras(); + if (extras != null) { + params = Arguments.fromBundle(extras); + } else { + params = Arguments.createMap(); + } + WritableMap fcm = Arguments.createMap(); + fcm.putString("action", newIntent.getAction()); + params.putMap("fcm", fcm); + if (currentIntent == null){ + //the first intent is initial intent that opens the app + sendEvent("FCMInitData", params); + } else { + sendEvent("FCMNotificationReceived", params); } - mIntent = newIntent; + currentIntent = newIntent; } @Override diff --git a/index.js b/index.js index 3200504bcefe29b99b68ecede81674952da65a58..d73264dfdd29294abb62d7a2459d8c3023469325 100644 --- a/index.js +++ b/index.js @@ -29,13 +29,17 @@ FCM.on = (event, callback) => { FCM.subscribeToTopic = (topic) => { FIRMessaging.subscribeToTopic(topic); -} +}; FCM.unsubscribeFromTopic = (topic) => { FIRMessaging.unsubscribeFromTopic(topic); -} +}; + +//once doesn't seem to work +DeviceEventEmitter.addListener('FCMInitData', (data)=>{ + FCM.initialData = data; +}); FCM.initialData = FIRMessaging.initialData; -FCM.initialAction = FIRMessaging.initialAction; module.exports = FCM; diff --git a/ios/RNFIRMesssaging.m b/ios/RNFIRMesssaging.m index f12b5b57e99ce872a8c7466a2ec8fb66fecd6f2a..b7d1aa39e2cb7cfe2852917af2acd8ce1eef020f 100644 --- a/ios/RNFIRMesssaging.m +++ b/ios/RNFIRMesssaging.m @@ -27,9 +27,7 @@ RCT_EXPORT_MODULE() - (NSDictionary *)constantsToExport { NSDictionary *initialNotification = [_bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] copy]; - - NSString *initialAction = [[initialNotification objectForKey:@"aps"] objectForKey:@"category"]; - return @{@"initialData": RCTNullIfNil(initialNotification), @"initialAction": RCTNullIfNil(initialAction)}; + return @{@"initialData": RCTNullIfNil(initialNotification)}; } - (void)dealloc