注意: 这是一个实验性/Alpha项目。

LibHoney

一个用 Swift 编写的,用于向 Honeycomb 发送事件的库。

安装

Cocoapods

CocoaPods 是 Cocoa 项目的依赖管理器。 您可以使用以下命令安装它

gem install cocoapods

要使用 CocoaPods 将 LibHoney 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

target '<Target name>' do
  # If you're using LibHoney with Objective-C, uncomment use_frameworks!
  # use_frameworks!  
  pod 'LibHoney', '~> 1.0'
end

然后运行以下命令

pod install

由于 LibHoney 依赖于 Alamofire,如果您在 Objective-C 中使用 LibHoney,您可能需要在 Pods 构建设置中为 Alamofire 设置 SWIFT_VERSION 变量。

用法

Swift

要使用 LibHoney,您必须首先使用您的 writeKey 和数据集名称配置该库。

AppDelegate 中的 didFinishLaunchingWithOptions

import LibHoney

// ...

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {    
    // other code...
    LibHoney.configure(writeKey: "<your write key>", dataset: "<your dataset name>")    
}

要发送事件,只需创建一个新事件并向其添加字段

let event = LibHoney.shared?.newEvent()
event?.add(key: "stringValue", value: "Hello, world")
event?.add(key: "intValue", value: 199)
event?.add(key: "boolValue", value: true)
event?.add(key: "doubleValue", value: 3.14159)
LibHoney.shared?.send(event)

如果 LibHoney 未配置,LibHoney.shared 将返回 nil。 使用上面的代码,您可以安全地绕过调试环境中的配置步骤。

要设置一个值,使其在每个事件中都被发送,请将该键添加到共享的 LibHoney 对象中

LibHoney.shared?.add(key: "user", value: "<user id>")

LibHoney 自动提取设备信息并将其与每个事件一起发送。 要禁用此行为

LibHoney.shared?.collectDeviceStats = false

Objective-C

要使用 LibHoney,您必须首先使用您的 writeKey 和数据集名称配置该库。

AppDelegate 中的 didFinishLaunchingWithOptions

@import LibHoney;

// ...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // other code...
    [LibHoney configureWithWriteKey:@"<your write key>" dataset:@"<your dataset name>"];    
}

要发送事件,只需创建一个新事件并向其添加字段

HoneyEvent* event = [LibHoney.shared newEvent];
[event addKey: @"stringValue" stringValue: @"Hello, world"];
[event addKey: @"intValue" intValue: 199];
[event addKey: @"boolValue" boolValue: true];
[event addKey: @"doubleValue" doubleValue: 3.14159];
[LibHoney.shared send: event];

如果 LibHoney 未配置,LibHoney.shared 将返回一个 nil 对象。

要设置一个值,使其在每个事件中都被发送,请将该键添加到共享的 LibHoney 对象中

[LibHoney.shared addKey:@"user" stringValue:@"<user Id>"];

LibHoney 自动提取设备信息并将其与每个事件一起发送。 要禁用此行为

LibHoney.shared.collectDeviceStats = NO;

贡献

我们非常乐意接受对 LibHoney 的功能、错误修复和其他更改的贡献。 请提交 issue 或 pull request 以及您的更改。 记得将您的名字添加到 CONTRIBUTORS 文件中!

所有贡献将根据 Apache License 2.0 发布。