Receive push notification

This topic explains how to set up your push notification service on your application. Complete this step if you are using the Identity Platform MFA methods push-to-accept, symbol-to-accept, or biometric. If you are using only TOTP, see "Generate offline TOTP" for steps.

At this point in the workflow, end users will request a second factor and must receive a push notification on their mobile device in your app.

Your mobile app must be registered to receive remote push notifications.

Note

Request permission from the app user to use notifications before continuing; iOS users must allow notifications or will not be able to see push notifications on their device.

After permission is granted, call registerForRemoteNotifications() to receive the needed device token for push notifications. For more information, see the external documents: Asking Permission to Use Notifications and Registering Your App with APNs.

let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
    
    if let error = error {
        // Handle the error here.
    }
    
    // Enable or disable features based on the authorization.
    UIApplication.shared.registerForRemoteNotifications()
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken  deviceToken: Data) {
   secureAuth.applicationUtil.pushToken = deviceToken.hexadecimal()
}

// Helper function to convert Data object to hexadecimal string format for pushToken
extension Data {
    /// Create hexadecimal `String` representation of `Data` object.
    ///
    /// - returns: `String` representation of this `Data` object.
    
    public func hexadecimal() -> String {
        return map { String(format: "%02x", $0) }
            .joined(separator: "")
    }
}

Next steps

Receive push notification