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
  • Start the SDK
  • Adding SDK’s HTTP headers to your gRPC requests
  • Handle block responses from your server
iOS SDKv2

Integration with gRPC [BETA]

Was this page helpful?
Previous

Migrating SDK from v1 to v2

Next
Built with

v2.x

The SDK can be integrated into gRPC projects.

Start the SDK

The automatic interceptor is not supported in gRPC, so you should disable requests interception by setting the PXPolicy/requestsInterceptedAutomaticallyEnabled to false.

1PXPolicy.requestsInterceptedAutomaticallyEnabled = false
2
3// call the start function...
4
5let policy = PXPolicy()
6policy.requestsInterceptedAutomaticallyEnabled = false
7
8// call the setPolicy function...

Adding SDK’s HTTP headers to your gRPC requests

In order to include the SDK’s HTTP headers in your gRPC requests, you should add them to your request’s metadata.

1let headers = PerimeterX.headersForURLRequest(forAppId: nil)
2var callOption = CallOptions()
3for (key, value) in headers {
4 callOption.customMetadata.replaceOrAdd(name: key, value: value)
5}
6// send you gRPC request with `callOption`...

Now, use the call option instance when you call your send your gRPC request.

Handle block responses from your server

After receiving an error in the server’s response, the gRPC library will throw an exception. pass the information to SDK with the handleResponse function.

1do {
2 // send your gRPC request...
3} catch {
4 if let statusError = error as? GRPC.GRPCStatus, let data = statusError.message?.data(using: .utf8) {
5 let response = HTTPURLResponse(url: URL(string: "https://your.server.domain")!, statusCode: 403, httpVersion: nil, headerFields: nil)!
6 PerimeterX.handleResponse(forAppId: nil, data: data, response: response)
7 }
8}