MissionControl 1.0.0

MissionControl 1.0.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2016年5月
SPM支持SPM

appculturetadija 维护。



Mission Control

用Swift编写(iOS、watchOS、tvOS、OSX)的超级强大的远程配置工具

由以下公司提供

您是否曾希望更改应用的一些配置参数而不必发布新版本?当然有!如果您的整个配置都在云端,并且可以灵活更改该多好?当然,将一些配置放在云端,然后 MissionControl 将为您处理其余的工作。

索引

功能

  • 轻松地使用远程(云)配置的优点为您的应用带来好处
  • 简单的灵活API让您可以从无配置、本地配置逐步过渡到远程配置
  • 自动缓存最新的远程设置以供离线使用(安全措施)
  • 在您真正需要最新配置(如现在)时,强制加载远程设置
  • 附有 单元测试
  • 附有文档

用法

初始配置

/// You should just launch shared instance of MissionControl on your app start.
/// Good place to do this is in your's AppDelegate's didFinishLaunchingWithOptions:

MissionControl.launch()

第一阶段 - 无配置

/// If you're starting from scratch, you could just start using MissionControl right away.
///
/// For anything that you find "configurable" (colors, fonts, alignment, values etc.),
/// instead of just hard-coding it, use helper accessors with setting key and fallback value.
///
/// Here are some examples:

let ready = ConfigBool("Ready", fallback: false)
let numberOfSeconds = ConfigInt("CountdownDuration", fallback: 10)
let launchForce = ConfigDouble("LaunchForce", fallback: 0.5)
let color = ConfigString("ReadyColor", fallback: "#7ED321")

第二阶段 - 本地配置

/// After some time, this adds up and you're probably ready to create some local config.
/// You should just define dictionary with setting keys and values and pass it on launch.
///
/// These settings will override whatever you put before in fallback value of accessors.
/// It doesn't need to contain all the stuff, the rest will just continue to use fallback values.

let config: [String : AnyObject] = [
    "Ready" : true,
    "LaunchForce" : 0.21
]

MissionControl.launch(localConfig: config)

第三阶段 - 远程配置

/// After some time, you decide to have more influence on these settings,
/// Yes, even if the app is already deployed. We get it!
///
/// But, you should create that backend part yourself (sorry).
/// Just make sure that you return JSON formatted key-value dictionary in response body.
/// Then, all you need to do is pass your's backend URL on launch.
///
/// After the first refresh (done automatically on launch) remote settings will be cached to disk.
/// These remote settings will override whatever you put in local config dictionary.
///
/// All helper accessors will respect these priority levels:
/// 1. Remote setting from memory (received in the most recent refresh).
/// 2. Remote setting from disk cache (if never refreshed in current app session (ex. offline)).
/// 3. Local setting from disk (defaults provided in `localConfig` on `launch`).
/// 4. Inline provided fallback value

let remoteURL = NSURL(string: "http://appculture.com/mission-control")!
MissionControl.launch(localConfig: config, remoteConfigURL: remoteURL)

强制加载远程设置

/// If you need, you can always call `refresh` manually to get the latest settings.
/// Good place to call this is in your AppDelegate's applicationWillEnterForeground: or applicationDidBecomeActive:

MissionControl.refresh()

/// There are also "async force remote" helper accessors which you can use
/// when it's really important to have the latest setting or abort everything.

ConfigBoolForce("Abort", fallback: true) { (forced) in
    if forced {
        self.stopCountdown()
        self.state = .Aborted
    }
}

监听变化

/// MissionControl can inform you whenever remote config is refreshed or failed to do so.
/// You can observe for these notifications, or become a MissionControl's delegate, whatever you prefer.

// MARK: - Notifications

let center = NSNotificationCenter.defaultCenter()
center.addObserver(self, selector: #selector(handleRefresh(_:)),
                   name: MissionControl.Notification.DidRefreshConfig, object: nil)
center.addObserver(self, selector: #selector(handleFail(_:)),
                   name: MissionControl.Notification.DidFailRefreshingConfig, object: nil)

// MARK: - MissionControlDelegate

MissionControl.delegate = self

func missionControlDidRefreshConfig(old old: [String : AnyObject]?, new: [String : AnyObject]) {
    /// do whatever you need to do
}

func missionControlDidFailRefreshingConfig(error error: ErrorType) {
    /// ignore or not, it's up to you
}

Demo

请查阅本仓库中的示例演示项目。
它类似于一个“火箭发射器”,但实际上并不能发射火箭,而是演示了使用MissionControl的强大功能。

让我来解释一下

  1. 第一屏是初始的“离线”状态,在此状态下您需要“连接”到基础(远程配置)。
  2. 当您按下“连接”按钮时,它将强制加载远程配置,并请求“准备就绪”布尔标志。
  3. 如果远程配置返回“准备就绪 = true”,则将进入“发射”屏幕,否则进入“失败”屏幕。
  4. 从“发射”屏幕,您可以启动“倒计时”。秒数也由远程配置提供。
  5. 在倒计时期间,每秒钟应用程序都会检查是否需要强制加载远程配置中的“中止”布尔标志来中止发射。是的,您可以从MissionControl远程中止发射。
  6. 倒计时结束后,您将看到一些精美的动画,这就结束了。

附言。一些颜色和其他值也通过远程配置提供。
以下是本演示中所使用的设置,以便您可以从您的服务器尝试中止发射。
只需确保将您的URL传递给MissionControl的launch:方法。

{
    "TopColor": "#000000",
    "BottomColor": "#4A90E2",
    "Ready": true,
    "CountdownDuration": 10,
    "Abort": false,
    "LaunchForce": 0.5,
    "OfflineColor": "#F8E71C",
    "ReadyColor": "#7ED321",
    "CountdownColor": "#F5A623",
    "LaunchedColor": "#BD10E0",
    "FailedColor": "#D0021B",
    "AbortedColor": "#D0021B"
}

那么,您准备好“实时”应用程序了吗?! 我们准备好了.

需求

  • Xcode 7.3+
  • iOS 8.0+

安装

  • 使用CocoaPods

    pod 'MissionControl'
  • Carthage

    github "appculture/MissionControl-iOS"
    
  • 手动安装

    只需将MissionControl.swift拖到您的项目中,然后开始使用它。

许可

MissionControl是以MIT许可证发布的。有关详细信息,请参阅LICENSE