AppVersionMonitor

repository·master·Indexed 42 days ago

https://github.com/eure/appversionmonitor

A lightweight iOS utility for monitoring app version changes. It enables developers to track installation history and detect if an app has been upgraded, downgraded, or newly installed via the AppVersionMonitor.sharedMonitor.state property. Supports iOS 8.0 or higher and provides tools to retrieve marketing versions and compare AppVersion instances.

Tokens
796
Snippets
6
Records
6
Agent score
4%

What's inside AppVersionMonitor

  1. Initialize AppVersionMonitor

    master

    To begin monitoring app versions, call startup() on the AppVersionMonitor.sharedMonitor instance, typically within your AppDelegate's applicationDidFinishLaunching method.

    // AppDelegate
    
    func applicationDidFinishLaunching(application: UIApplication) {
        AppVersionMonitor.sharedMonitor.startup()
    }
  2. Compare AppVersion instances

    master

    The AppVersion type supports comparison operators (>, <) against other AppVersion instances or raw version strings. This allows you to check if the current version is newer or older than a specific target.

    AppVersion.marketingVersion > AppVersion("1.2.3")
    AppVersion("1.2.3") < AppVersion("3.2.1")
    AppVersion("1.2.3") < "3.2.1"
  3. Check app version status and handle updates

    master

    Use AppVersionMonitor.sharedMonitor.state to determine the relationship between the current installation and previous versions. This is useful for triggering data migrations or tutorials.

    Available states:

    • .Installed: The app was just installed (first time).
    • .NotChanged: The version is the same as the previous installation.
    • .Upgraded(previousVersion: AppVersion): The app version has increased. Use this to trigger data migrations.
    • .Downgraded(previousVersion: AppVersion): The app version has decreased. Use this to purge incompatible data.
    switch AppVersionMonitor.sharedMonitor.state {
    case .Installed:
        // Start tutorial
    
    case .NotChanged:
        // Nothing to do
    
    case .Upgraded(let previousVersion: AppVersion):
        // Migrate App Data
    
    case .Downgraded(let previousVersion: AppVersion):
        // Purge App Data
    }
  4. Retrieve installed version history

    master

    Access the list of previously installed versions using AppVersionMonitor.sharedMonitor.installedVersions. This returns an array of AppVersion objects.

    let installedVersions: [AppVersion] = AppVersionMonitor.sharedMonitor.installedVersions
  5. Get the current Marketing Version

    master

    Use AppVersion.marketingVersion to retrieve the current app's version (corresponding to CFBundleShortVersionString). You can access the raw string representation via the .versionString property.

    let currentVersion: AppVersion = AppVersion.marketingVersion
    let versionString: String = AppVersion.marketingVersion.versionString // "1.2.3"