此 SDK 允许您将 Reclaim 的应用内验证流程集成到您的 SwiftUI 应用程序中。
复制以下 URL 并使用它将 Swift Package Manager (SPM) 依赖项添加到 Xcode 项目中
https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git
File
> Add Package Dependency...
。Add Package Dependency
”对话框中,将 URL `https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git` 粘贴到对话框右上角的“Search or Enter package URL
”字段中。3. 点击“Add Package
”。4. 在另一个窗口中,在“Add to Targets
”部分选择您的**应用目标**,然后点击“Add package
”。
这样就完成了 Reclaim InApp SDK 的安装。现在按照以下步骤将必要的框架链接到您的 Xcode 项目。
Podfile
中为您的项目定义一个全局平台,版本为 13.0 或更高版本。platform :ios, '13.0'
Podfile
以覆盖 ReclaimInAppSdk 的默认版本(可选)pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git', :tag => '0.1.4'
pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git'
pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git', :commit => '184d41628026768feb703dc7bb9a3d913c6b271e'
pod 'ReclaimInAppSdk', :git => 'https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git', :branch => 'main'
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
pod install
。*.xcworkspace
文件以处理项目。并构建项目。*.xcworkspace
文件。在您目标的“Build Settings
”下的“Build Options
”部分,将“User Script Sandboxing
”设置为“No
”,然后再次构建项目。有关更多信息,请查看Reclaim Example - SwiftUI with CocoaPods,了解如何在结合 CocoaPods 的 SwiftUI 应用程序中使用 SDK 的完整示例。
选择一个包版本
.package(url: "https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git", from: "0.1.2")
或选择主分支
.package(url: "https://github.com/reclaimprotocol/reclaim-inapp-ios-sdk.git", branch: "main")
.product(name: "ReclaimInAppSdk", package: "ReclaimInAppSdk")
*.xcworkspace
文件,请在 Xcode 中打开 YourApp.xcworkspace
。验证您打开的是 MyApp.xcworkspace 而不是 MyApp.xcodeproj。.xcworkspace 文件包含 CocoaPod 依赖项,而 .xcodeproj 文件不包含。如果您没有 *.xcworkspace
文件,请在 Xcode 中打开 YourApp.xcodeproj
。Cmd + B
。当您在物理设备上运行调试可执行文件时,您的应用性能将受到严重影响。修复此问题需要在您的 Xcode 项目 xcscheme 中进行简单的更改。
GODEBUG
asyncpreemptoff=1
此方法不推荐,但如果您不想将环境变量添加到 xcscheme,则可能很有用。
要在您的项目中使用 ReclaimInAppSdk,请按照以下步骤操作
import ReclaimInAppSdk
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
)
)
在 ReclaimVerification.Request.*
API 中提供了更多创建请求对象的方法。
// 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)
返回的结果是一个 ReclaimVerification.Response
对象。如果验证成功,此对象包含一个带有 proofs、exception 和 sessionId 的响应。
如果验证被取消或失败,结果将包含一个 exception。
您可以使用 ReclaimVerification.Response
对象来获取 proof、exception 和 sessionId。
let proof = result.response.proofs
let exception = result.response.exception
let sessionId = result.response.sessionId
如果验证成功,proof 将包含您需要存储在数据库中的数据。
如果验证被取消或失败,exception 将包含错误详细信息。
在上述 API 中,ReclaimVerification.Request.*
、ReclaimVerification.startVerification
或 ReclaimVerification.startVerificationFromUrl
也可能抛出错误。错误可能是以下之一
ReclaimVerificationError.cancelled
:验证已被用户取消。ReclaimVerificationError.dismissed
:验证已被 SDK 关闭。ReclaimVerificationError.failed(let error)
:验证因错误而失败。ReclaimVerificationError.sessionExpired
:验证会话已过期。您可以使用 do-catch
块来处理错误。例如
do {
let result = try await ReclaimVerification.startVerification(request)
} catch ReclaimVerificationError.cancelled {
print("Verification cancelled")
} catch ReclaimVerificationError.dismissed {
print("Verification dismissed")
}
有关完整示例,请参阅Reclaim Example - SwiftUI。
您可以使用 ReclaimOverrides
通过 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")
}
}
}
要升级到新版本的 Reclaim InApp SDK,请按照以下步骤操作
0.1.4
。当发布具有 API 更改的新版本时,将提供迁移指南。