Skip to content

VersionsTracker is a Swift Library, which tracks install version history of app and os version.

License

Notifications You must be signed in to change notification settings

martnst/VersionsTracker

Repository files navigation

VersionsTracker

[CI Status](https://travis-ci.org/Martin Stemmle/VersionsTracker) Version License Platform

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

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.

About

VersionsTracker is a Swift Library, which tracks install version history of app and os version.

Resources

License

Stars

Watchers

Forks

Packages

No packages published