BulletTrainClient 1.0.1

BulletTrainClient 1.0.1

由以下人员维护:Ben RometschMatthew ElwellDaniel WichettBen Rometsch



Bullet Train iOS Client

BulletTrainClient 是一个用 Swift 编写的 iOS Client,用于 Bullet-Train。使用特性标志和远程配置有信心地发布功能。

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖项管理器。有关用法和安装说明,请访问他们的网站。要使用 CocoaPods 将 Alamofire 集成到您的 Xcode 项目中,请在其 Podfile 中指定它。

pod 'BulletTrainClient', '~> 1.0'

用法

注册

Bullet Train 上注册并创建一个项目。记录下 API 密钥,这是您配置应用所需的。

初始化

在您的应用程序代理(通常是 AppDelegate.swift)中添加

import BulletTrainClient
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

BulletTrain.shared.apiKey = "<YOUR_API_KEY>"
// The rest of your launch method code
}

现在您可以获取项目中的功能标志。例如,列出并打印所有标志

BulletTrain.shared.getFeatureFlags() { (result) in
    switch result {
    case .success(let flags):
        for flag in flags {
            let name = flag.feature.name
            let value = flag.value
            print(name, "=", value ?? "nil")
        }
    case .failure(let error):
        print(error)
    }
}

通过名称检索功能值

BulletTrain.shared.getFeatureValue(withID: "test_feature2", forIdentity: nil) { (result) in
    switch result {
    case .success(let value):
        print(value ?? "nil")
    case .failure(let error):
        print(error)
    }
}

这些方法还可以指定特定的身份以检索用户注册的值。请参阅身份管理,使用forIdentity参数。

检索特定身份的属性(请参阅属性

BulletTrain.shared.getTraits(forIdentity: "[email protected]") {(result) in
    switch result {
    case .success(let traits):
        for trait in traits {
            let name = trait.key
            let value = trait.value
            print(name, "=", value)
        }
    case .failure(let error):
        print(error)
    }
}