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
      • Callbacks from the SDK
      • How to retry blocked requests
      • Multiple AppIDs support
      • Integration with React Native
      • Integration with gRPC [BETA]
      • Migrating SDK from v1 to v2
    • 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
  • v2.x
iOS SDKv2

Integration with React Native

Was this page helpful?
Previous

Integration with gRPC [BETA]

Next
Built with

v2.x

The SDK can be integrated into React Native projects.

  1. Add the SDK to your Android project as described above.

  2. The automatic interceptor is not supported in React Native, so any request from the JavaScript code has to be handled manually.

  3. Disable the automatic interception as described above.

  4. Create a native module as described here.

  5. Create a function that pass the HTTP headers from the HUMAN SDK to the JavaScript code. Here is an example:

    1RCT_EXPORT_METHOD(getHTTPHeaders:(RCTResponseSenderBlock)callback) {
    2 NSDictionary<NSString *, NSString *> *headers = [PerimeterX headersForURLRequestForAppId:nil];
    3 NSData *data = [NSJSONSerialization dataWithJSONObject:headers options:0 error:nil];
    4 NSString *json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    5 callback(@[json]);
    6}
  6. In your JavaScript code, send your request with those HTTP headers. Here is an example:

    1PerimeterXModule.getHTTPHeaders(async headers => {
    2 const obj = JSON.parse(headers);
    3 const url = 'https://my.request.com'
    4 const response = await fetch(url, {
    5 method: 'GET',
    6 headers: obj,
    7 })
    8});
  7. Next, pass the response back to the native module. Here is an example:

    1RCT_EXPORT_METHOD(handleResponse:(NSString *)response code:(NSInteger)code url:(NSString *)url) {
    2 NSData *data = [response dataUsingEncoding:NSUTF8StringEncoding];
    3 NSHTTPURLResponse *httpURLResponse = [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:url] statusCode:code HTTPVersion:nil headerFields:nil];
    4 [PerimeterX handleResponseForAppId:nil data:data response:httpURLResponse];
    5}

    1const json = await response.json();
    2PerimeterXModule.handleResponse(JSON.stringify(json), response.status, url);