Callbacks from the SDK
v2.x
The SDK provides callbacks that will help you to handle events from it. There are 4 types of events:
- The SDK is ready.
- A request was blocked.
- A challenge was solved by the user.
- A challenge was cancelled by the user.
The SDK is ready
This event means that the SDK was finished the start process successfully. When calling the PerimeterX/start(appId:delegate:enableDoctorCheck:completion:)
function, you should provide a completion handler. Once the handler is called with success == true
you know that the SDK is ready. In addition, you can register to this event in other places within your code, using the PerimeterX/addInitializationFinishedCallback(forAppId:callback:)
function. Here is an example:
PerimeterX.addInitializationFinishedCallback(forAppId: nil) {
print("PerimeterX is ready")
}
[PerimeterX addInitializationFinishedCallbackForAppId:nil callback:^{
NSLog(@"PerimeterX is ready");
}];
You can call the PerimeterX/addInitializationFinishedCallback(forAppId:callback:)
when the SDK is already ready. In this case, the callback will be called immediately.
A request was blocked
This event occurred when a request was blocked by PerimeterX. Notice that this event is only for native URL requests. URL requests which are origin from web views won't trigger this event.
There are two ways to receive this event:
- PerimeterX's delegate - The
delegate
object that conform to thePerimeterXDelegate
protocol should implement thePerimeterXDelegate/perimeterxDidRequestBlocked(forAppId:)
function. - Register to the event - you can register to this event in other places within your code, using the
PerimeterX/registerCallbackForRequestBlockedEvent(forAppId:callback:)
function. This function returns a Registration ID which can be used to unregister from this event with thePerimeterX/unregisterCallbackForRequestBlockedEvent(forAppId:registrationId:)
. Here is an example:
let requestBlockedEventRegistrationId = PerimeterX.registerCallbackForRequestBlockedEvent {
print("Request Blocked Event")
}
NSString *requestBlockedEventRegistrationId = [PerimeterX registerCallbackForRequestBlockedEventForAppId:nil callback:^{
NSLog(@"Request Blocked Event");
}];
A challenge was solved by the user
This event occurred when a challenge was solved by the user. Notice that this event is only for native URL requests. URL requests which are origin from web views won't trigger this event.
There are two ways to receive this event:
- PerimeterX's delegate - The
delegate
object that conform to thePerimeterXDelegate
protocol should implement thePerimeterXDelegate/perimeterxDidChallengeSolved(forAppId:)
function. - Register to the event - you can register to this event in other places within your code, using the
PerimeterX/registerCallbackForChallengeSolvedEvent(forAppId:callback:)
function. This function returns a Registration ID which can be used to unregister from this event with thePerimeterX/unregisterCallbackForChallengeSolvedEvent(forAppId:registrationId:)
. Here is an example:
let challengeSolvedEventRegistrationId = PerimeterX.registerCallbackForChallengeSolvedEvent {
print("Challenge Solved Event")
}
NSString *challengeSolvedEventRegistrationId = [PerimeterX registerCallbackForChallengeSolvedEventForAppId callback:^{
NSLog(@"Challenge Solved Event");
}];
A challenge was cancelled by the user
This event occurred when a challenge was cancelled by the user. Notice that this event is only for native URL requests. URL requests which are origin from web views won't trigger this event.
There are two ways to receive this event:
- PerimeterX's delegate - The
delegate
object that conform to thePerimeterXDelegate
protocol should implement thePerimeterXDelegate/perimeterxDidChallengeCancelled(forAppId:)
function. - Register to the event - you can register to this event in other places within your code, using the
PerimeterX/registerCallbackForChallengeCancelledEvent(forAppId:callback:)
function. This function returns a Registration ID which can be used to unregister from this event with thePerimeterX/unregisterCallbackForChallengeCancelledEvent(forAppId:registrationId:)
. Here is an example:
let challengeCancelledEventRegistrationId = PerimeterX.registerCallbackForChallengeCancelledEvent {
print("Challenge Cancelled Event")
}
NSString *challengeCancelledEventRegistrationId = [PerimeterX registerCallbackForChallengeCancelledEventForAppId callback:^{
NSLog(@"Challenge Cancelled Event");
}];
Updated 12 days ago