VersionsTracker
[](https://travis-ci.org/Martin Stemmle/VersionsTracker)
Keeping track of version installation history made easy.
Features
- 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 )
Example
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.
Requirements
- Xcode 7.0+
- iOS 8.0+
- Semantic Versioning
Installation
CocoaPods
VersionsTracker is available through CocoaPods. To install it, simply add the following line to your Podfile
:
pod "VersionsTracker"
Carthage
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"
Usage
Initialization
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
}
Get the current versions with build and install date
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)")
Get the version history
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)")
Check version changes easily
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.
Compare Version
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.
Author
Martin Stemmle, [email protected]
License
VersionsTracker is available under the MIT license. See the LICENSE file for more info.