Ketch 移动 SDK 提供了 Ketch 的同意和偏好管理功能的 iOS 和 Android 原生集成。
此 SDK 支持 iOS 版本 15.0 及以上。
所需的最小 Xcode 版本为 15.0。
所需的最小 Swift 版本为 5.5。
使用 Mobile SDK 需要 Ketch 组织账户,并已配置 应用属性。
SDK 提供了一个预先注册的示例组织,用于快速测试和评估。虽然很方便,但建议您尽快切换到自己的组织。自己的组织可以确保隔离、安全性、可伸缩性和定制支持,优化您的开发过程。只需注册一个新账户,更新 SDK 配置,即可无缝过渡到生产就绪和长期使用。
沙箱组织和配置可用于开发和测试
组织:ketch_samples
属性:ios
Boot.js: https://#/web/v3/config/ketch_samples/ios/boot.js
网站: https://ketch-com.github.io/testing-sites/prod/ketch_samples_ios.html
Swift 包管理器 是一种用于自动化 Swift 代码分发的工具,它集成到 swift
编译器中。
将 Ketch iOS SDK 添加为依赖项至您的 Package.swift
中或 Xcode 中的包列表。
dependencies: [
.package(url: "https://github.com/ketch-com/ketch-ios.git", .upToNextMajor(from: "3.0.0"))
]
var ketch: Ketch?
var ketchUI: KetchUI?
private func setupKetch(advertisingIdentifier: UUID) {
let ketch = KetchSDK.create(
organizationCode: "#{your_org_code}#",
propertyCode: "#{your_property}#",
environmentCode: "#{your_environment}#",
identities: [
Ketch.Identity(key: "aaid", value: "00000000-0000-0000-0000-000000000000"),
Ketch.Identity(key: "email", value: "[email protected]"),
Ketch.Identity(key: "account_id", value: "1234")
]
)
self.ketch = ketch
}
ketchUI = KetchUI(ketch: ketch)
如果您使用 SwiftUI,设置 KetchUI.webPresentationItem 为 View 中的 ketchView
var body: some View {
VStack {
...
}
.ketchView(model: $ketchUI.webPresentationItem)
}
如果您使用 UIKit,以模态展示 KetchUI
func presentKetchUI() {
// 1. collect needed parameter
let params: [KetchUI.ExperienceOption] = [
.environment("production"),
.language(code: "EN")
]
// 2. reload ketch
ketchUI.reload(with: params)
}
在 UIKit 中,您负责 KetchUI 的展示/消失,因此请确保您已订阅 Ketch 事件
ketchUI.eventListener = self
extension ViewController: KetchEventListener {
// present the Ketch View Controller
func onShow() {
guard let presentationItem = ketchUI.webPresentationItem else {
return
}
present(presentationItem.viewController, animated: false)
}
// handle dssmiss
func onDismiss() {
dismiss(animated: false)
}
func onEnvironmentUpdated(environment: String?) { }
func onRegionInfoUpdated(regionInfo: String?) { }
func onJurisdictionUpdated(jurisdiction: String?) { }
func onIdentitiesUpdated(identities: String?) { }
func onConsentUpdated(consent: KetchSDK.ConsentStatus) { }
func onError(description: String) { }
func onCCPAUpdated(ccpaString: String?) { }
func onTCFUpdated(tcfString: String?) { }
func onGPPUpdated(gppString: String?) { }
}
extension KetchUI {
public enum ExperienceOption {
/// Enables console logging by Ketch components
case logLevel(LogLevel)
/// Forces an experience to show
case forceExperience(ExperienceToShow)
/// Overrides environment detection and uses a specific environment
case environment(String)
/// ISO-3166 country code overrides region detection and uses a specific region
case region(code: String)
/// Jurisdiction code overrides jurisdiction detection and uses a specific jurisdiction
case jurisdiction(code: String)
/// ISO 639-1 language code, with optional regional extension overrides language detection and uses a specific language
case language(code: String)
/// Default tab that will be opened
case preferencesTab(PreferencesTab)
/// Comma separated list of tabs to display on the preference experience
case preferencesTabs(String)
/// URL string for SDK, including `https://`
case ketchURL(String)
public enum ExperienceToShow: String {
case consent, preferences
}
public enum PreferencesTab: String, CaseIterable {
case overviewTab, rightsTab, consentsTab, subscriptionsTab
}
public enum LogLevel: String, Codable {
case trace, debug, info, warn, error
}
}
}
var params: [KetchUI.ExperienceOption] = [
.region(code: "US"),
.language(code: "EN"),
.forceExperience(.consent),
.jurisdiction(code: "default"),
.environment("production")
]
ketchUI.reload(with: params)
public protocol KetchEventListener: AnyObject {
func onShow()
func onDismiss()
func onEnvironmentUpdated(environment: String?)
func onRegionInfoUpdated(regionInfo: String?)
func onJurisdictionUpdated(jurisdiction: String?)
func onIdentitiesUpdated(identities: String?)
func onConsentUpdated(consent: KetchSDK.ConsentStatus)
func onError(description: String)
func onCCPAUpdated(ccpaString: String?)
func onTCFUpdated(tcfString: String?)
func onGPPUpdated(gppString: String?)
}
ketchUI.eventListener = #{myEventListener}#
我们提供了一个完整的示例应用程序来展示集成:[此处](https://github.com/ketch-sdk/ketch-samples/tree/main/ketch-ios/iOS%20Ketch%20SDK%20SwiftUI)