Push Notification Token Updates
HYPR uses Firebase as a push notification provider when authenticating users for web accounts. In some circumstances, the Firebase registration token can change, rendering the server unable to push notifications to the device.
SDK for Android
To allow Android applications to automatically update the push notification token when required, app\commonlibraries\src\main\java\com\hypr\commonlibraries\HyprWrapper.kt
includes the following interface:
/**
* Start action to update Push Token in all App Profiles that exist in the
* Application. If there are websites registered on multiple RP Applications
* across multiple RP Servers, then all of them will get the Push Token updated.
* There is no UI Spinner for this operation on the SDK level.
*
* @param activity Activity that is kicking off the action and handling the result
* @param firebaseToken Push Token to update in the HYPR server
*/
fun updateFirebaseTokenIfNeeded(activity: Activity, onCompletion: (isSuccess: Boolean, hyprStatusResult: HyprStatusResult?) -> Unit) {
if (HyprApp.getDbAdapter().isUpdateFirebaseTokenNeeded(activity)) {
val properties = HyprAppProperties(activity)
HyprActions.getInstance().updatePushToken(activity, properties.firebaseToken, object : HyprActionCallbacks.HyprActionCallback {
override fun onSuccess(statusResult: HyprStatusResult) {
onCompletion(true, statusResult)
}
override fun onFailure(statusResult: HyprStatusResult) {
onCompletion(false, statusResult)
}
})
}
}
The \webaccountunlock
module overrides the onNewToken
method in the CustomFirebaseMessagingService
class (\app\webaccountunlock\src\main\java\com\hypr\webaccountunlock
), extending the FirebaseMessagingService
class:
/**
* This is called when we generate a new registration token. The registration
* token is used for determining to which device to send the push notification
*/
override fun onNewToken(token: String) {
HyprPushNotificationAdapter.getInstance().onNewPushChannelId(applicationContext, token)
}
You must use a local flag to track whether or not a token refresh is needed. Check this flag in your App initialization sequence before making the [updatePushToken
](./../sdkHyprModels/sdkHyprModelsAndroid/sdk-hypr-models-android-hyprapiactionadapter#updatePushToken
SDK for iOS
HYPR uses Firebase as a push notification provider when authenticating users for web accounts. In some circumstances, the Firebase registration token can change, rendering the server unable to send push notifications to the device.
To allow iOS applications to update the push notification token when required, HYPR SDK for iOS implements the Firebase messaging delegate method for registration token updates:
- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
HyprLogDebug(@"FCM registration token: %@", fcmToken);
NSDictionary* userInfo = @{HYPRPushNotificationTokenKey : fcmToken};
[[NSNotificationCenter defaultCenter] postNotificationName:HYPRPushNotificationRegistrationUpdated object:nil userInfo:userInfo];
}
Firebase Messaging Delegate
Send the notification to HYPRPushNotificationRegistrationUpdated
with the Firebase Cloud Messaging token value for key HYPRPushNotificationTokenKey
in the user info dictionary.