KKMonitor
入门

iOS

将 Measure SDK 集成到您的 iOS 应用中。

最低要求

名称版本
Xcode15.0+
最低 iOS 部署版本12.0+
Swift 版本5.10+

1. 获取凭证

在 Dashboard 的 应用 页面创建一个新应用,并复制它的 API URLAPI Key

2. 安装 SDK

// In Package.swift
.package(url: "https://github.com/measure-sh/measure.git", branch: "ios-v0.12.1")
# In your Podfile
pod 'measure-sh'

MeasureSDK 仅支持静态链接。如果你的 Podfile 使用了 use_frameworks!,请安装 cocoapods-pod-linkage 插件(gem install cocoapods-pod-linkage),并将 measure-sh 配置为静态链接:

# In your Podfile
plugin 'cocoapods-pod-linkage'

target 'YourApp' do
  use_frameworks!
  pod 'measure-sh', :linkage => :static
end

3. 初始化 SDK

尽早初始化以捕获早期崩溃和准确的启动时间指标。

// In your AppDelegate's application(_:didFinishLaunchingWithOptions:)
import Measure

let clientInfo = ClientInfo(apiKey: "<apiKey>", apiUrl: "<apiUrl>")
let config = BaseMeasureConfig()
Measure.initialize(with: clientInfo, config: config)
// In your AppDelegate's application:didFinishLaunchingWithOptions:
#import <Measure/Measure.h>

ClientInfo *clientInfo = [[ClientInfo alloc] initWithApiKey:@"<apiKey>" apiUrl:@"<apiUrl>"];
BaseMeasureConfig *config = [[BaseMeasureConfig alloc]
    initWithEnableLogging:YES
    autoStart:YES
    requestHeadersProvider:NULL
    maxDiskUsageInMb:50
    enableFullCollectionMode:NO
    enableDiagnosticMode:NO
    enableDiagnosticModeGesture:NO];
[Measure initializeWith:clientInfo config:config];

4. 验证安装

之后添加测试崩溃Measure.initialize,运行应用程序,并确认它到达您的仪表板。

// In your AppDelegate, after Measure.initialize.
// The 2-second delay gives the SDK time to flush the crash event.
// Remove this after the crash appears in your dashboard.
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
    fatalError("Test crash from Measure")
}

确认仪表板中出现崩溃后,删除测试崩溃代码。