Skip to content

Commit

Permalink
Fix for token not receive in android
Browse files Browse the repository at this point in the history
according to the recommendations in wix#109
  • Loading branch information
charles001636 committed May 3, 2018
1 parent 2c71cd9 commit cd964d7
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
import static com.wix.reactnativenotifications.Defs.LOGTAG;
import static com.wix.reactnativenotifications.Defs.TOKEN_RECEIVED_EVENT_NAME;

import com.wix.reactnativenotifications.core.AppLifecycleFacade;
import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder;

public class GcmToken implements IGcmToken {

final protected Context mAppContext;
final protected AppLifecycleFacade mAppLifecycleFacade = AppLifecycleFacadeHolder.get();

protected static String sToken;

Expand Down Expand Up @@ -121,12 +125,11 @@ protected String getSenderIdFromManifest() {
}

protected void sendTokenToJS() {
final ReactInstanceManager instanceManager = ((ReactApplication) mAppContext).getReactNativeHost().getReactInstanceManager();
final ReactContext reactContext = instanceManager.getCurrentReactContext();
final ReactContext reactContext = mAppLifecycleFacade.getRunningReactContext();

// Note: Cannot assume react-context exists cause this is an async dispatched service.
if (reactContext != null && reactContext.hasActiveCatalystInstance()) {
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(TOKEN_RECEIVED_EVENT_NAME, sToken);
}
// Note: Cannot assume react-context exists cause this is an async dispatched service.
if (reactContext != null && reactContext.hasActiveCatalystInstance()) {
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(TOKEN_RECEIVED_EVENT_NAME, sToken);
}
}
}

0 comments on commit cd964d7

Please sign in to comment.