ForgeRock SDKs

Enable push notifications

The ForgeRock Authenticator module uses Apple’s "Apple Push Notification service" (APNs) to receive push notifications.

Each instance of your application requires a unique device token in order to receive the push notifications from AM.

For information about obtaining an APNs device token, see Registering Your App with APNs.

You can also see how to obtain the device registration token in the ForgeRock Authenticator sample.

Once you register your application with APNs, use code similar to the following to enable notifications:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Register Push Notification for your app in AppDelegate.swift
    let center = UNUserNotificationCenter.current()
    center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in }
    application.registerForRemoteNotifications()
    return true
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // Upon successful registration and receiving device token from APNs, register the token to the Authenticator module
    FRAPushHandler.shared.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    // Upon receiving an error from APNs, notify Authenticator module to properly update the status
    FRAPushHandler.shared.application(application, didFailToRegisterForRemoteNotificationsWithError: error)
}
Copyright © 2010-2022 ForgeRock, all rights reserved.