VersionsTracker
[](https://travis-ci.org/Martin Stemmle/VersionsTracker)
轻松追踪版本安装历史。
特性
- 不仅追踪市场版本,还跟踪构建号和安装日期
- 跟踪应用和操作系统版本
- 访问当前版本
- 检查版本更新和初次运行
- 无需作为 Singleton 使用
- 能够使用自定义NSUserDefaults(例如,用于与扩展共享)的能力
示例
要运行示例项目,请首先克隆仓库,然后从示例目录中运行 pod install
。试玩样本应用程序的版本和构建号。
需求
- Xcode 7.0+
- iOS 8.0+
- 语义化版本控制
安装
CocoaPods
VersionsTracker可通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile
pod "VersionsTracker"
Carthage
Carthage是一个去中心化的依赖管理器,它会构建您的依赖并提供二进制框架。将以下行添加到您的Cartfile
github "martnst/VersionsTracker"
使用方法
初始化
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if iDontMindSingletons {
VersionsTracker.initialize(trackAppVersion: true, trackOSVersion: true)
}
else {
// make sure to update the version history once once during you app's life time
VersionsTracker.updateVersionHistories(trackAppVersion: true, trackOSVersion: true)
}
return true
}
获取当前版本号及构建和安装日期
let versionsTracker = iDontMindSingletons ? VersionsTracker.sharedInstance : VersionsTracker()
let curAppVersion : Version = versionsTracker.appVersion.currentVersion
print("Current marketing version is \(curAppVersion.versionString) (Build \(curAppVersion.buildString)) and was first launched \(curAppVersion.installDate)")
获取版本历史
let versionsTracker = iDontMindSingletons ? VersionsTracker.sharedInstance : VersionsTracker()
let appVersions: [Version] = versionsTracker.appVersion.versionHistory
let firstOSVerion : Version = versionsTracker.osVersion.versionHistory.first!
print("The very first time the app was launched on iOS \(firstOSVerion.versionString) on \(firstOSVerion.installDate)")
轻松检查版本更改
let versionsTracker = iDontMindSingletons ? VersionsTracker.sharedInstance : VersionsTracker()
switch versionsTracker.appVersion.changeState {
case .installed:
// 🎉 Sweet, a new user just installed your app
// ... start tutorial / intro
print("🆕 Congratulations, the app is launched for the very first time")
case .notChanged:
// 😴 nothing as changed
// ... nothing to do
print("🔄 Welcome back, nothing as changed since the last time")
case .updated(let previousVersion: Version):
// 🙃 new build of the same version
// ... hopefully it fixed those bugs the QA guy reported
print("🆙 The app was updated making small changes: \(previousVersion) -> \(versionTracker.currentVersion)")
case .upgraded(let previousVersion):
// 😄 marketing version increased
// ... migrate old app data
print("⬆️ Cool, its a new version: \(previousVersion) -> \(versionTracker.currentVersion)")
case .downgraded(let previousVersion):
// 😵 marketing version decreased (hopefully we are not on production)
// ... purge app data and start over
print("⬇️ Oohu, looks like something is wrong with the current version to make you come back here: \(previousVersion) -> \(versionTracker.currentVersion)")
}
由于同时跟踪构建信息,因此可以检测其更新。然而,版本的构建部分被视为任意字符串。这是为了支持任何构建号,从整数到git提交哈希。因此无法确定构建变更的方向。
比较版本
let versionsTracker = iDontMindSingletons ? VersionsTracker.sharedInstance : VersionsTracker()
let curAppVersion : Version = versionsTracker.appVersion.currentVersion
curAppVersion >= Version("1.2.3")
curAppVersion >= "1.2.3"
Version("1.2.3") < Version("3.2.1")
curAppVersion != Version("1.2.3", buildString: "B19")
具有相同市场版本但不同构建的版本不相等。
作者
马了丁·斯特梅尔, [email protected]
许可协议
VersionsTracker 在 MIT 许可协议下可用。更多信息请参阅 LICENSE 文件。