braze-inc / braze-react-native-sdk

Public repo for the Braze React Native SDK
https://www.braze.com
Other
64 stars 84 forks source link

[Feature]: provide a `registerIOSPushToken` #221

Closed artyorsh closed 8 months ago

artyorsh commented 1 year ago

What problem are you facing?

In our app, we use background-fetch to sync iOS/Android push tokens with servers while the app is not in use. This way we try to achieve up-to-date tokens with different platforms, so that there is no issue with sending notifications to "inactive" users.

With Braze react-native SDK, this scenario is a bit complicated to achieve, because the only way to sync push token with Platform, is through native Braze.Notifications.register, which accepts token as Data.

For most of the RN apps, the way to get APNS token on JS side, is either through @react-native-community/push-notification-ios, or @react-native-firebase/messaging packages - both of them return token as string. Please provide a function that will work in a similar to registerAndroidPushToken way, accept an APNs string and call Braze.Notifications.register with token transformed to Data.

Workarounds

Since the only way to use Braze.Notifications.register is binding to native didRegisterForRemoteNotificationsWithDeviceToken, we can trigger this function by requesting notification permission (even if already granted) with any of requestPermission functions of any permission/notification packages. That's not complicated to implement, but adds a layer of implicity to the codebase.

Ideal Solution

It would be very helpful to have registerIOSPushToken on JS side.

Other Information

The source of the problem for us was "Uninstall measurement" feature, that started to send silent notifications to users, who most likely had outdated APNs tokens. This resulted with Braze marking users "Unregistered" (see on screenshot) and affected our campaign segmentation.

image
jerielng commented 1 year ago

Hi @artyorsh, thanks for raising this. We'd be happy to add support for this method on iOS and have filed a ticket internally to track this effort.

We'll keep you updated in this thread. Please let us know in the meantime if you have any further questions.

RyanSept commented 1 year ago

+1

vineyardbovines commented 1 year ago

We've had an open support ticket with Braze for almost 3 weeks now with an issue that this solution would help resolve.

hokstuff commented 1 year ago

Hi all,

Updating this thread - We have slotted in work to add a new API in the Javascript layer to accept a token (String) and pass that to Braze. From the original request, it sounds like this will be helpful when using other 3rd party libraries in React Native that already store the push token (sent from APNs), and this new API will make it easier to pass that token to Braze. This way, integrators won't need to grab that token directly from the iOS native layer in order to forward it to Braze's servers.

We will keep you updated when we release this feature!

hokstuff commented 1 year ago

Hi all,

We have just released React Native SDK version 7.0.0 which adds a new API Braze.registerPushToken() to the Javascript layer for this use case.

Thanks for your patience!

gvash commented 8 months ago

Hi @hokstuff, I was trying to leverage Braze.registerPushToken() but for some reason it is saying BadToken. I wanted to learn how can I get this token, which is passed inside Braze.registerPushToken()

lowip commented 8 months ago

Hi @hokstuff, I was trying to leverage Braze.registerPushToken() but for some reason it is saying BadToken. I wanted to learn how can I get this token, which is passed inside Braze.registerPushToken()

Hi @gvash, it seems that the iOS implementation of Braze.registerPushToken() is faulty. We have a fix in review that should be part of the next release. I'm reopening this issue and we will update here once the fix is released.

Thank you for your patience!

gvash commented 8 months ago

@lowip, Thanks for the quick reply, Can you please let me know from where can I get this token for Braze.registerPushToken()?

lowip commented 8 months ago

@gvash, at this time we recommend against using the JavaScript Braze.registerPushToken() as the provided token is erroneously transformed into an invalid token when passing the value to our native layer. Instead, you can use the method shown in our sample app here.

The Braze.registerPushToken() fix has been merged in our internal repository and will be part of the next update.

jerielng commented 8 months ago

Hey @gvash, this should now be resolved in version 9.1.0! Let us know if you have any other concerns, but we'll go ahead and close out this issue!