customerio / customerio-reactnative

MIT License
25 stars 13 forks source link

Issue with CustomerIO.identify() and token registration #75

Closed rivaros closed 1 year ago

rivaros commented 1 year ago

SDK version: 2.0.0-beta1

Environment: not relevant

Are logs available?

Describe the bug If my assumption is correct, registration of device token in CustomerIO happens in call to MessagingPush.shared.messaging(), below, but only if user is identified (otherwise token is not registered).

   // Register device on receiving a device token (FCM)
   @objc(didReceiveRegistrationToken:fcmToken:)
   public func didReceiveRegistrationToken(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
     MessagingPush.shared.messaging(messaging, didReceiveRegistrationToken: fcmToken)
   }

If it is true, that makes a problem, because didReceiveRegistrationToken call from FIRMessaging delegate happens on the very app launch, when obviously user identification happens on a later stage.

So even if later we call CusromerIO.identify() and even we can call something like firebase.messaging().registerDeviceForRemoteMessages(), device would be registered for notifications, but method didReceiveRegistrationToken will not be triggered again (as FCM and APN tokens were generated on app start) So device would not be added to user account in customerio.

To Reproduce Basically any scenario where didReceiveRegistrationToken happens on launch, and CustomerIO.identify( on later stage

Expected behavior There should be some check on CusromerIO.identify(): if FCM token received & device is registered for remote notification, SDK should detect and add the token to CustomerIO

Screenshots N/A

Additional context N/A

ami-aman commented 1 year ago

Hi @rivaros

Thanks for reaching out.

You are correct with your assumption that in certain scenarios like yours, the device is not get registered as expected. This is happening because of lifecycle differences between react native and native modules, that means that the native methods are called before react native lifecycle starts.

I would like to let you know that our team is working on a similar issue here and we are hopeful to come up with a fix very soon.

lj-cio commented 1 year ago

Hi @rivaros, while we continue working on the lifecycle differences, we just pushed version 2.0.1 that gives you the flexibility to add a device token directly using the method CustomerIO.registerDeviceToken(token). Take a look and let us know if this unblocks you in short term. Thank you!