Receive push notifications
You receive Apple push notifications by using the application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
method in AppDelegate
.
Use the FRAPushHandler.shared.application(:didReceiveRemoteNotification)
method to handle RemoteNotification
.
The method returns a PushNotification
object, which contains the accept
and deny
methods
to handle the authentication request:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// Once you receive the remote notification, handle it with FRAPushHandler to get the PushNotification object.
// If RemoteNotification does not contain the expected payload structured from AM, the Authenticator module does not return the PushNotification object.
if let notification = FRAPushHandler.shared.application(application, didReceiveRemoteNotification: userInfo) {
// With the PushNotification object, you can either accept or deny
notification.accept(onSuccess: {
}) { (error) in
}
}
}
The PushNotification
class provides the following properties for obtaining values from the payload received in the push notification:
Property | Purpose |
---|---|
|
Returns a JSON string containing the values specified in the Custom Payload Attributes property of the Push Sender node. |
|
Returns the string specified in the User Message property of the Push Sender node, such as |
|
Returns a JSON string containing additional context information when the Share Context info property is enabled in the Push Sender node. Possible attributes in the JSON string are as follows:
Ensure you check these attributes for Example:
|
|
Returns a PushType enum value that specifies the type of push notification to present to the user. This value is based on the configuration of the Push Type property in the Push Sender node. Possible values are:
|
|
Returns an array of integers that matches those displayed on the login screen and populates the |
The class also provides the timeAdded
property that contains a timestamp of when the authentication server generated the push authentication payload.
The PushNotification
class provides an accept
method for handling a PushType.default
authentication request:
pushNotification.accept(onSuccess: {
// called when accepting the push authentication request was successful.
}, onError: { (error) in
// called when denying the push authentication request, or it has failed.
})
For PushType.challenge
authentication requests, use the following accept
method that receives the challenge as a parameter:
public func accept(challengeResponse: String,
onSuccess: @escaping SuccessCallback,
onError: @escaping ErrorCallback) {}
For PushType.biometric
authentication requests, use the following accept
method that processes the biometric authentication request:
public func accept(title: String,
allowDeviceCredentials: Bool,
onSuccess: @escaping SuccessCallback,
onError: @escaping ErrorCallback) {}
Use the pushType
enum to determine which to call:
if notification.pushType == .challenge {
notification.accept(challengeResponse: "34", onSuccess: successCallback, onError: errorCallback)
} else if notification.pushType == .biometric {
notification.accept(title: "title", allowDeviceCredentials: trueonSuccess: successCallback, onError: errorCallback)
} else {
notification.accept(onSuccess: successCallback, onError: errorCallback)
}