Skip to content

Callbacks⚓︎

The app will receive callbacks from the Mobile SDK in order to provide feedback to the user or to request their input.

Android⚓︎

To listen for callbacks from the Mobile SDK, implement the NextAuthObserver interface and register your observer with the Mobile SDK. Do not forget to unregister the observer when you are finished with it.

... implements NextAuthObserver {

    //register observer
    NextAuth.getNextAuth().addObserver(this);

    //unregister observer
    NextAuth.getNextAuth().removeObserver(this);

    @Override
    public void onCallback(Callback callback) {
        //TODO implement logic
    }

}

Optionally, you can also extend the AbstractCallbackHandler class and directly listen for specific callbacks.

... extends AbstractCallbackHandler implements NextAuthObserver {
    //register observer
    NextAuth.getNextAuth().addObserver(this);

    //unregister observer
    NextAuth.getNextAuth().removeObserver(this);

    @Override
    public void onCallback(Callback callback) {
        callback.trigger(this)
    }

    @Override
    public void onFlowUpdate(SecondFactor callback) {
         //TODO implement logic
    }

    ...
}
Method When Expected Response
FlowUpdate The flow had been updated. Provide the user’s input if the flow’s State is WAIT_FOR_INPUT, depending on CurrentInteraction. See Interactions for more details.
SessionUpdate A session has been updated.
AccountUpdate An account has been updated.
AccountDeleted An account has been deleted.
TokenResult A token has been received as a result of the getToken() call.
RetrievedMessages The list of messages has been received from the Message Center as a result of a retrieveMessages() call.
Error An error that is unrelated to a flow has occurred.
Panic An unrecoverable error has occurred.

iOS⚓︎

On iOS, the Mobile SDK has three mechanisms to notify your app when user interaction is required or when an entity has been updated. To notify your app that user interaction is required, the common delegate pattern1 is used. When an entity has been updated, the information is broadcasted using NSNotificationCenter2. As a third mechanism, flow updates can be received as a Combine Publisher.

Delegate⚓︎

Whenever the Mobile SDK requires some interaction from the user, it will call the relevant method on its configured delegate. It is therefore important that you include a class in your app which conforms to the NextAuthDelegate interface. You should also ensure that you assign an instance of this class to NextAuth.default.delegate. Because the delegate methods will need to interact with the UI, a possible approach is to build a view controller which will always be present in the view hierarchy and to have it conform to the following protocol.

Method When
didReceive The Mobile SDK returns the requested upstream token.
didReturn An error occurs which should be displayed to the user.
didThrow The Mobile SDK encounters a fatal exception.

Notifications⚓︎

The following notification will be broadcasted on the listed event. When posting the notification, the updated instance will be included and will therefore be accessible using NSNotification.object.

Notification When
NotificationNames.accountUpdate An account has been updated (or deleted, before Mobile SDK v1.8.0).
NotificationNames.accountDelete An account has been deleted (available from Mobile SDK v1.8.0).
NotificationNames.sessionUpdate The status of a session has changed.

Publishers⚓︎

The following Combine Publishers will deliver elements to subscribers, enabling you to build event-processing chains.

Publisher When Expected Response
FlowService.flowPublisher The flow has been updated. Provide the user’s input if the flow’s State is WAIT_FOR_INPUT, depending on currentInteraction. See Interactions for more details.