Bundle Info Versioning badge-version

badge-docs badge-swift-pm badge-license badge-twitter

  1. Introduction
  2. Requirements
  3. Installation
  4. Usage Examples
  5. Contribute
  6. Meta

Introduction

BundeInfoVersioning is a lightweight package that allows you to observe changes in the Info.plist file when there is an app update.

Requirements

  • iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 11.0+
  • Swift 5.1+

Installation

Swift Package Manager

You can use the Swift Package Manager to install BundeInfoVersioning by adding it to your Package.swift file:

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/nsagora/bundle-info-versioning", majorVersion: 1),
    ]
)

Manually

To manually add this library in your project, just drag the Sources folder into the project tree.

Usage examples

Check for CFBundleShortVersionString updates and show a What’s new like screen each time the user updates the app:

import BundleInfoVersioning

let bundleInfoVersioning = BundleInfoVersioning()

bundleInfoVersioning.check(forKeyPath: "CFBundleShortVersionString") { (_ , newVersion: String?) in
    self.showWhatsNew(in: newVersion)
}

Check for CFBundleVersion updates and track in the analytics when the app is installed or updated:

import BundleInfoVersioning

let bundleInfoVersioning = BundleInfoVersioning(bundle: .main)

bundleInfoVersioning.check(forKeyPath: "CFBundleVersion") { (old: String?, new: String?) in
    if old == nil {
        Analytics.install(version: new)
    }
    else {
        Analytics.update(from: old, to: new)
    }
}

Check for a custom key path (e.g. NSAgora/DatabaseVersion) updates and execute the migration code for the data base.

import BundleInfoVersioning

let bundleInfoVersioning = BundleInfoVersioning()

bundleInfoVersioning.check(forKeyPath: "NSAgora/DatabaseVersion") { (_: Int?, _: Int?) in
    self.migrateDataBase()
}

Advanced usage

The BundeInfoVersioning class allows to specify the Bundle on which will be observing the Info.plist changes.

By default it is initialized with the .main bundle.

Specify bundle “` swift import BundleInfoVersioning let bundleInfoVersioning = BundleInfoVersioning(bundle: .main) bundleInfoVersioning.check(forKeyPath: "CFBundleVersion”) { (old: String?, new: String?) in if old == nil { Analytics.install(version: new) } else { Analytics.update(from: old, to: new) } } “`

The BundeInfoVersioning framework comes with a build-in storage system, implemented on top of UserDefaults.

However, if it doesn’t fit the apps needs, you can implement a custom storage by conforming to the Storage protocol.

Custom storage ”` swift import BundleInfoVersioning class MyStorage: Storage { func set(value: T?, for key: String) { UserDefaults.standard.set(value, forKey: key) } func getValue(for key: String) -> T? { return UserDefaults.standard.value(forKey: key) as? T } } let storage = MyStorage() let bundleInfoVersioning = BundleInfoVersioning(bundle: .main, storage: storage) bundleInfoVersioning.check(forKeyPath: “NSAgora/DatabaseVersion”) { (old: Int?, new: Int?) in self.migrateDataBase() } “`

Contribute

We would love you for the contribution to BundleInfoVersioning, check the LICENSE file for more info.

Meta

This project is developed and maintained by the members of iOS NSAgora, the community of iOS Developers of Iași, Romania.

Distributed under the MIT license. See LICENSE for more information.

[https://github.com/nsagora/bundle-info-versioning]