✨Works out of the box guarantee. If you face any issue at all, hit us up on Telegram and we will write the integration for you.
logoReclaim Protocol Docs
Reclaim InApp SDKs

iOS SDK

This SDK allows you to integrate Reclaim's in-app verification process into your SwiftUI application.

Prerequisites

  • An iOS application source code (Support for iOS 13 or later).
  • An iOS device running iOS 13 or later.
  • A Reclaim account where you've created an app and have the app id, app secret.
  • A provider id that you've added to your app in Reclaim Devtools.

Example

Installation

1. Adding Reclaim InApp SDK to your Xcode Project

Copy the following URL and use it to add Swift Package Manager (SPM) dependency into the Xcode project:

https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git
How to add a Swift Package Manager (SPM) dependency to your Xcode project:
  1. In your Xcode Editor's toolbar, click on File > Add Package Dependency....
Add a dependency to your Xcode project
  1. In the Add Package Dependency dialog box, paste the URL https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git into the Search or Enter package URL field on the top right corner of dialog box.
Add a dependency to your Xcode project
  1. Click Add Package.
  2. In the other window, select your app target in the Add to Targets section and then click Add package.
Add a dependency to your Xcode project

This should complete the installation of the Reclaim InApp SDK. Now follow the steps below to link the necessary frameworks to your Xcode project.

Note
  • It's worth noting that you should commit the swiftpm folder that will be built and more specifically that the Package.resolved file should be included in your source control/git.

Method 2: When working with an Xcode Workspace project with CocoaPods:

  1. Make sure to define a global platform for your project in your Podfile with version 13.0 or higher.
platform :ios, '13.0'
  1. Add the following to your Podfile:
  • From a specific tag (recommended):
pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git', :tag => '0.1.2'
  • or from git HEAD (Alternative):
pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git'
  • or from a specific commit (Alternative):
pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git', :commit => '184d41628026768feb703dc7bb9a3d913c6b271e'
  • or from a specific branch (Alternative):
pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git', :branch => 'main'
  1. After adding the dependency, your podfile may look like this:
platform :ios, '13.0'
 
target 'GitPodSwiftUIExample' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
 
  # Pods for GitPodSwiftUIExample
  pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git', :commit => '184d41628026768feb703dc7bb9a3d913c6b271e'
 
  target 'GitPodSwiftUIExampleTests' do
    inherit! :search_paths
    # Pods for testing
  end
 
  target 'GitPodSwiftUIExampleUITests' do
    # Pods for testing
  end
 
end
  1. Run pod install.
  2. Open the *.xcworkspace file to work on the project. And build the project.
  3. Your build may fail due to an error like this:
Xcode build error due to CocoaPods
  1. To fix this, open the *.xcworkspace file in Xcode. In your target's Build Settings, under Build Options Section, set User Script Sandboxing to No and build the project again.
Xcode build error due to CocoaPods
  1. Your project should build successfully.

Method 3: When working with a Swift Package Manager manifest:

Either select a package version:

.package(url: "https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git", from: "0.1.2")

Or select the main branch:

.package(url: "https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git", branch: "main")
Select a product:
  • ReclaimInAppSdk
.product(name: "ReclaimInAppSdk", package: "ReclaimInAppSdk")

Build the project.

  1. If you have a *.xcworkspace then open YourApp.xcworkspace in Xcode. Verify that you're opening MyApp.xcworkspace and not opening MyApp.xcodeproj. The .xcworkspace file has the CocoaPod dependencies, the .xcodeproj doesn't. If you don't have a *.xcworkspace then open YourApp.xcodeproj in Xcode.
  2. Select Product > Build or press Cmd + B.

2. Fixing performance issues

Your app performance will be severely impacted when you run debug executable on a physical device. Fixing this requires a simple change in your Xcode project xcscheme.

  1. Open your project in Xcode.
  2. Click on the project target.
  3. Click on the Scheme dropdown.
Edit current xcscheme in Xcode
  1. Click on the Edit Scheme button.
  2. Click on the Run tab.
  3. Click on the Arguments tab and check the Environment Variables section.
Enable Debug executable in Xcode
  1. Add the following environment variable:
    • Key: GODEBUG
    • Value: asyncpreemptoff=1
  2. Click on the Close button in the dialog and build the project.
  3. Run the app on a physical device.

Method 2: Disable "Debug executable"

This method is not recommended but could be useful if you don't want to add environment variables to the xcscheme.

  1. Open your project in Xcode.
  2. Click on the project target.
  3. Click on the Scheme dropdown.
Edit current xcscheme in Xcode
  1. Click on the Edit Scheme button.
  2. Click on the Run tab.
  3. Uncheck the Debug executable checkbox.
Enable Debug executable in Xcode

4. Use ReclaimInAppSdk in your project

To use ReclaimInAppSdk in your project, follow these steps:

  1. Import the ReclaimInAppSdk module into your Swift file.
import ReclaimInAppSdk
  1. Create a request object.
let request = ReclaimVerification.Request.params(
    try .init(
        /// You can use the appId and secret from Reclaim Devtools to create a request.
        /// Providing appId and secret here in this initializer is optional.
        /// If you don't provide it, the SDK will use the appId and secret from the Info.plist file.
        // appId: "YOUR_APP_ID_FROM_RECLAIM_DEVTOOLS",
        // secret: "YOUR_APP_SECRET_FROM_RECLAIM_DEVTOOLS",
        /// This is the provider id that you've added to your app in Reclaim Devtools.
        /// The verification flow will use the provider information fetch by this provider id.
        providerId: providerId
    )
)

More ways to create a request object are available in the ReclaimVerification.Request.* apis.

  1. Start the verification flow.
// This is the function that starts the verification flow.
// This may fail if device screen is getting shared.
let result = try await ReclaimVerification.startVerification(request)

The returned result is a ReclaimVerification.Response object. This object contains a response that has proofs, exception, and the sessionId if the verification is successful.

If the verification is cancelled or failed, the result will contain an exception.

You can use the ReclaimVerification.Response object to get the proof, exception, and sessionId.

let proof = result.response.proofs
let exception = result.response.exception
let sessionId = result.response.sessionId

If the verification is successful, the proof will contain the data that you need to store in your database.

If the verification is cancelled or failed, the exception will contain the error details.

In the above apis, ReclaimVerification.Request.*, ReclaimVerification.startVerification or ReclaimVerification.startVerificationFromUrl can also throw an error. The error can be one of the following:

  • ReclaimVerificationError.cancelled: The verification was cancelled by the user.
  • ReclaimVerificationError.dismissed: The verification was dismissed by the sdk.
  • ReclaimVerificationError.failed(let error): The verification failed due to an error.
  • ReclaimVerificationError.sessionExpired: The verification session expired.

You can handle the error by using a do-catch block. For example:

do {
    let result = try await ReclaimVerification.startVerification(request)
} catch ReclaimVerificationError.cancelled {
    print("Verification cancelled")
} catch ReclaimVerificationError.dismissed {
    print("Verification dismissed")
}

For a complete example, see the Reclaim Example - SwiftUI.

Overrides | Advanced Usage

You can use the ReclaimOverrides to customize the verification flow with ReclaimVerification.setOverrides.

func setOverrides() {
    Task { @MainActor in
        do {
            try await ReclaimVerification.setOverrides(
                appInfo: ReclaimOverrides.ReclaimAppInfo(
                    appName: "Overriden Example",
                    appImageUrl: "https://placehold.co/400x400/png"
                )
                // Add other overrides here
            )
        } catch {
            print("unexpected failure error details: \(error)")
            showAlert(message: "Could not set overrides")
        }
    }
}

Upgrading

To upgrade to a new version of the Reclaim InApp SDK, follow these steps:

  1. Make sure you have the latest version of the Reclaim InApp SDK. Currently the latest version is v0.1.2.
  2. Incase of any problems: remove package, clear build, restart Xcode, and add package again.

Migration guides will be available when a new version with API changes is released.