[](https://travis-ci.org/Martin Stemmle/VersionsTracker)
Keeping track of version installation history made easy.
- Track not just marketing version, but also build number and install date
- Track both App and OS version
- Access current version
- Check for version updates and first launch
- No use as Singleton required
- Ability to use custom NSUserDefaults (e.g. for sharing it with extensions )
To run the example project, clone the repo, and run pod install
from the Example directory first. Play with the Sample app's version and build numbers.
- Xcode 7.0+
- iOS 8.0+
- Semantic Versioning
VersionsTracker is available through CocoaPods. To install
it, simply add the following line to your Podfile
:
pod "VersionsTracker"
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. Add the following line to your 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)")
}
Since the build is also kept track off, it enables detecting updates of it as well. However, the build fraction of a version is treated as an arbitrary string. This is to support any build number, from integer counts to git commit hashes. Therefor there is no way to determine the direction of a build change.
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")
Versions with the same marketing version but different build are not equal.
Martin Stemmle, [email protected]
VersionsTracker is available under the MIT license. See the LICENSE file for more info.