iOS SDK - 初始化 SDK
以下这行代码将为您安装追踪器,并随之安装 SDK,让您能够使用追踪器的所有功能。
Cocoapods
Section titled Cocoapods pod 'OpenReplay', '~> 1.0.17'
Swift Package Manager
Section titled Swift Package Managerdependencies: [
.package(url: "https://github.com/openreplay/ios-tracker.git", from: "1.0.17"),
]
在实例化 OpenReplay 的追踪器时,您可以提供多个配置选项来自定义录制及录制体验的诸多方面。您必须在构造函数中设置 projectKey 选项。您可以从 OpenReplay 控制台的 ‘Preferences > Projects’ 中获取该值。
添加追踪代码
Section titled 添加追踪代码将以下代码添加到您的 AppDelegate.swift 文件中:
// AppDelegate.swift
import OpenReplay
//...
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// not required if you're using our SaaS version
OpenReplay.shared.serverURL = "https://your.instance.com/ingest"
// check out our SDK docs to see available options
OpenReplay.shared.start(projectKey: "projectkey", options: .defaults)
// ...
return true
}
设置触摸监听器
Section titled 设置触摸监听器// SceneDelegate.Swift
import OpenReplay
// ...
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let contentView = ContentView()
.environmentObject(TodoStore())
if let windowScene = scene as? UIWindowScene {
let window = TouchTrackingWindow(windowScene: windowScene) // <<<< here
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}
有关更多详细信息,请参阅如何在 iOS 回放中脱敏数据。
初始化选项
Section titled 初始化选项crashes: Bool启用崩溃分析(crashlytics)。analytics: Bool启用对标记视图的分析追踪。performances: Bool启用性能监听器。logs: Bool启用日志监听器。screen: Bool启用屏幕录制器。wifiOnly: Bool强制追踪器仅在用户拥有 wifi 连接时启动。