diff --git a/android/react-native-fcm.iml b/android/react-native-fcm.iml
index d4e484327ba45ccdd790671346e3ba4b7f46e5f9..841500a257be8c1061e0fce73b6a77b86df2cf13 100644
--- a/android/react-native-fcm.iml
+++ b/android/react-native-fcm.iml
@@ -65,14 +65,6 @@
-
-
-
-
-
-
-
-
@@ -81,6 +73,14 @@
+
+
+
+
+
+
+
+
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 a5354c80f8986e16e3554e014c3a3273c908c1ac..27b6ca656f3906fe1dd5b7c74db829192f7d4017 100644
--- a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
+++ b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
@@ -15,23 +15,44 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.messaging.RemoteMessage;
+import android.os.Bundle;
import android.util.Log;
import android.content.Context;
+import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-public class FIRMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
+public class FIRMessagingModule extends ReactContextBaseJavaModule {
private final static String TAG = FIRMessagingModule.class.getCanonicalName();
+ Intent mIntent;
- public FIRMessagingModule(ReactApplicationContext reactContext) {
+ public FIRMessagingModule(ReactApplicationContext reactContext, Intent intent) {
super(reactContext);
- getReactApplicationContext().addLifecycleEventListener(this);
+ mIntent = intent;
- registerNotificationHandler();
registerTokenRefreshHandler();
+ registerMessageHandler();
+ }
+
+ @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;
}
@Override
@@ -73,7 +94,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
}, intentFilter);
}
- private void registerNotificationHandler() {
+ private void registerMessageHandler() {
IntentFilter intentFilter = new IntentFilter("com.evollu.react.fcm.ReceiveNotification");
getReactApplicationContext().registerReceiver(new BroadcastReceiver() {
@@ -96,17 +117,4 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
}
}, intentFilter);
}
-
- @Override
- public void onHostResume() {
- }
-
- @Override
- public void onHostPause() {
- }
-
- @Override
- public void onHostDestroy() {
-
- }
}
diff --git a/android/src/main/java/com/evollu/react/fcm/FIRMessagingPackage.java b/android/src/main/java/com/evollu/react/fcm/FIRMessagingPackage.java
index f6ab4e22eb85f9ba7a2d97012534adb9feef309d..5c980c6ca040f89372897f1339c222c0e65e1936 100644
--- a/android/src/main/java/com/evollu/react/fcm/FIRMessagingPackage.java
+++ b/android/src/main/java/com/evollu/react/fcm/FIRMessagingPackage.java
@@ -1,5 +1,7 @@
package com.evollu.react.fcm;
+import android.content.Intent;
+
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
@@ -11,16 +13,20 @@ import java.util.Collections;
import java.util.List;
public class FIRMessagingPackage implements ReactPackage {
+ Intent mIntent;
+
+ public FIRMessagingPackage(){
+ }
- public FIRMessagingPackage() {
+ public FIRMessagingPackage(Intent intent){
+ mIntent = intent;
}
@Override
- public List createNativeModules(
- ReactApplicationContext reactContext) {
+ public List createNativeModules(ReactApplicationContext reactContext) {
List modules = new ArrayList<>();
- modules.add(new FIRMessagingModule(reactContext));
+ modules.add(new FIRMessagingModule(reactContext, mIntent));
return modules;
}
diff --git a/index.js b/index.js
index eba05126e89ca558d3382c4f3d3c424521537d45..8088e4ceca22fa72be039df2554689a761f32880 100644
--- a/index.js
+++ b/index.js
@@ -5,8 +5,6 @@ var {NativeModules} = React;
var FIRMessaging = NativeModules.RNFIRMessaging;
-console.log(NativeModules.RNFIRMessaging);
-
class FCM {
static getFCMToken() {
@@ -19,4 +17,7 @@ class FCM {
}
+FCM.initialData = FIRMessaging.initialData;
+FCM.initialAction = FIRMessaging.initialAction;
+
module.exports = FCM;
\ No newline at end of file
diff --git a/ios/RNFIRMesssaging.m b/ios/RNFIRMesssaging.m
index 04ae918b6d818fe0f06079d9b0cc440d91fcbb5f..72267969f1de61fd19ae393b71ba4576624a306b 100644
--- a/ios/RNFIRMesssaging.m
+++ b/ios/RNFIRMesssaging.m
@@ -26,9 +26,10 @@ RCT_EXPORT_MODULE()
- (NSDictionary *)constantsToExport
{
- NSDictionary *initialNotification =
- [_bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] copy];
- return @{@"initialNotification": RCTNullIfNil(initialNotification)};
+ NSDictionary *initialNotification = [_bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] copy];
+
+ NSString *initialAction = [[initialNotification objectForKey:@"aps"] objectForKey:@"category"];
+ return @{@"initialData": RCTNullIfNil(initialNotification), @"initialAction": RCTNullIfNil(initialAction)};
}
- (void)dealloc