visionOS Integration (Sheet)
visionOS Integration (Sheet)
visionOS Integration (Sheet)
In this article we will learn how integrate the SDK to your visionOS app.
The sheet option will present the HUMAN challenge in a sheet over the window the request has left from, this will disable the user to continue any interactions in the screen until the challenge is solved.
You will need to add the sheet integration code to every view sending requests that might be blocked.
We will cover the following topics:
Some features, including the Doctor App, Automatic Interceptor and Hybrid App support, are not available in the SDK for visionOS yet. We will add those features soon.
App’s init function on visionOS.Here is an example of how it should be:
Don’t forget to change the <APP_ID> to your own AppID.
Let’s talk about what we have in the code here:
HSPolicy instance. This object is used to configure the SDK’s behavior.start function of the SDK. We provide the following parameters:
Note: If your app communicates with several servers that have different AppID, you can call the HumanSecurity/start(appIds:policy:) function which allow you to pass an array of AppIDs. You should specify the relevant AppID for each API call in the SDK.
HSChallengeView for each view that could have blocked requests. The HSChallengeView must be the first component in the body. The HSChallengeView will handle the presentation of the challenge.HSChallengeModelViewHelper/registerError(error:uuid:callback:) function for every block error you get. You need to provide a unique identifier that represents the view which the HSChallengeView is placed into. You may provide a callback that will be called once the challenge was solved/cancelled.HSChallengeModelViewHelper/unregister(uuid:) when your view is disappearing. This will release related resources to prevent a memory leak.Here is an example of how it should be:
Let’s talk about what we have in the code here:
View:
HSChallengeView to the ContentView’s body.HSChallengeModelViewHelper/unregister(uuid:) function when the ContentView is disappearing.Model / HTTP client:
ViewModel.View Model:
challengeUUID) for the view.HSChallengeModelViewHelper/registerError(error:uuid:callback:) function when we get an error (the SDK handles blocked requests only and ignores other kinds of error).Handle it as a failure.
Your app should handle the blocked request as a failure. However, you should consider that other windows in your app’s UI are still shown while the challenge is presented to the user. If the request was triggered by a user’s action, you should make it clear that the user may try again the same action.
Use the handler callback to write analytics, logs, etc.
You may use the handler callback to retry the original request when appropriate. You should consider the following:
HumanSecurity/blockError(response:data:forAppId:) function.HSChallengeModelViewHelper/registerError(error:uuid:callback:) function with the view’s uuid. Otherwise, the SDK won’t present a challenge to the user.You can set custom parameters in order to configure HUMAN’s backend with additional parameters.
Those parameters can be set with a dictionary (iOS) or a hash map (Android), with the key “custom_param[x]” where [x] is a number between 1-10.
You should call the HSBotDefender/setCustomParameters(parameters:forAppId:) only after the HumanSecurity/start(appId:policy:) function was already called.
Here is an example of how it should be:
In order to enable Account Defender, you should set the UserID of your current logged-in user in the SDK.
Here is an example of how it should be:
In order to allow Account Defender to protect the user’s account, your app has to provide the SDK with outgoing URL requests.
Let’s talk about what we have in the code here:
HSAccountDefender/registerOutgoingUrlRequest(url:forAppId:) function before we send the URL request.You can set additional data in order to configure HUMAN’s backend with additional parameters.
Those parameters can be set with a dictionary.
You should call the HSAccountDefender/setAdditionalData(parameters:forAppId:) only after the HumanSecurity/start(appId:policy:) function was already called.