iOS SDK - 初始化 SDK

iOS 追踪器构造方法的配置选项

iOS SDK ⁠-⁠ 初始化 SDK

以下这行代码将为您安装追踪器,并随之安装 SDK,让您能够使用追踪器的所有功能。

  pod 'OpenReplay', '~> 1.0.17'
dependencies: [
    .package(url: "https://github.com/openreplay/ios-tracker.git", from: "1.0.17"),
]

在实例化 OpenReplay 的追踪器时,您可以提供多个配置选项来自定义录制及录制体验的诸多方面。您必须在构造函数中设置 projectKey 选项。您可以从 OpenReplay 控制台的 ‘Preferences > Projects’ 中获取该值。

将以下代码添加到您的 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
			}
// 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 回放中脱敏数据

  • crashes: Bool 启用崩溃分析(crashlytics)。
  • analytics: Bool 启用对标记视图的分析追踪。
  • performances: Bool 启用性能监听器。
  • logs: Bool 启用日志监听器。
  • screen: Bool 启用屏幕录制器。
  • wifiOnly: Bool 强制追踪器仅在用户拥有 wifi 连接时启动。

如果您对此过程有任何疑问,欢迎在我们的 Slack 上联系我们,也可以查看我们的论坛