For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
HUMAN DashboardHUMAN WebsiteRequest a Demo
Product GuidesEnforcer GuidesMobile SDKAPI ReferenceCustomer support
Product GuidesEnforcer GuidesMobile SDKAPI ReferenceCustomer support
    • Overview
  • Mobile SDK (for Android, iOS, and visionOS)
    • Android changelog
    • iOS, iPadOs, & visionOS changelog
    • Expo changelog
    • React Native Wrapper changelog
  • iOS SDK
    • What's New
      • How to integrate the SDK in your application
      • How to verify the integration in your app with the SDK
      • Manual integration
      • Handle block responses from the server
      • How to retry requests that were blocked
      • Hybrid App support
      • Enable support for Account Defender
      • Multiple AppIDs support
      • Integration with React Native
      • Integration with Flutter
      • Integration with Ionic
      • Integration with gRPC
      • Migrating SDK from v2 to v3
    • How to test your app with the SDK
  • Android SDK
    • What's New
    • How to test your app with the SDK
LogoLogo
Login
Login
HUMAN DashboardHUMAN WebsiteRequest a Demo
On this page
  • v3.0
  • Start the SDK
  • Setup a plugin
  • Pass the SDK’s HTTP headers to the JavaScript code and handle the response
iOS SDKv3

Integration with Ionic

Was this page helpful?
Previous

Integration with gRPC

Next
Built with

v3.0

The SDK can be integrated into Ionic projects.

Start the SDK

The automatic interceptor is not supported in Ionic, so any request from the JavaScript code has to be handled manually. Here is an example:

1do {
2 let policy = PXPolicy()
3 policy.urlRequestInterceptionType = .none
4 try PerimeterX.start(appId: "<APP_ID>", delegate: self, policy: policy)
5}
6catch {
7 print("error: \(error)")
8}

Setup a plugin

Configure the plugin in JavaScript. Here is an example:

1export interface PerimeterxPlugin {
2 getHttpHeaders(): Promise<{ value: string }>;
3 handleResponse():Promise<{ value: string }>;
4}
5
6const PerimeterX = registerPlugin<PerimeterxPlugin>('PerimeterX');

Setup a plugin in order to handle calls from the JavaScript code. Here is an example:

HUMANManager.swift:

1import Foundation
2import Capacitor
3import PerimeterX_SDK
4
5@objc(PerimeterxManagerPlugin)
6class PerimeterxManagerPlugin: CAPPlugin {
7
8 static let shared = PerimeterxManagerPlugin()
9
10 func start() {
11 do {
12 let policy = PXPolicy()
13 policy.urlRequestInterceptionType = .none
14 policy.doctorCheckEnabled = false
15 try PerimeterX.start(appId: "PXj9y4Q8Em", delegate: nil, policy: policy)
16 }
17 catch {
18 print("error: \(error)")
19 }
20 }
21
22 @objc func getHttpHeaders(_ call: CAPPluginCall) {
23 call.resolve(PerimeterX.headersForURLRequest()!)
24 }
25
26 @objc func handleResponse(_ call: CAPPluginCall) {
27 let response = call.getString("value") ?? ""
28 let data = response.data(using: .utf8)
29 let httpURLResponse = HTTPURLResponse(url: URL(string: "https://fake.url.com")!, statusCode: 403, httpVersion: nil, headerFields: nil)
30 let handled = PerimeterX.handleResponse(response: httpURLResponse!, data: data!) { challengeResult in
31 call.resolve(["value": challengeResult == .solved ? "solved" : "cancelled"])
32 }
33 if !handled {
34 call.resolve(["value": "false"])
35 }
36 }
37}

HUMANManagerPlugin.m:

1#import <Foundation/Foundation.h>
2#import <Capacitor/Capacitor.h>
3
4CAP_PLUGIN(PerimeterxManagerPlugin, "PerimeterX",
5 CAP_PLUGIN_METHOD(getHttpHeaders, CAPPluginReturnPromise);
6 CAP_PLUGIN_METHOD(handleResponse, CAPPluginReturnPromise);
7)

Pass the SDK’s HTTP headers to the JavaScript code and handle the response

In your JavaScript code, call those functions for every URL request to add those HTTP headers and handle the response. Here is an example:

1const sendUrlRequest = async () => {
2 const result = await PerimeterX.getHttpHeaders()
3 const json = JSON.parse(JSON.stringify(result))
4 const map = new Map(Object.entries(json))
5 console.log(map)
6
7 var xhr = new XMLHttpRequest()
8 xhr.addEventListener('load', async () => {
9 const challengeResult = await PerimeterX.handleResponse({ value: xhr.responseText })
10 console.log("result = ", JSON.parse(JSON.stringify(challengeResult)))
11 })
12 xhr.open('GET', 'https://sample-ios.pxchk.net/login')
13 for (const [key, value] of map) {
14 xhr.setRequestHeader(key, value as string)
15 }
16 xhr.send()
17};