BundleInfoVersioning
public class BundleInfoVersioning
BundleInfoVersioning checks at runtime if, for a given keypath, there have been changes in the info.plist file from the associated Bundle.
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)
}
-
Creates and returns a new
BundleInfoVersioninginstance for a givenBundleobject.Check for
CFBundleShortVersionStringupdates 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) }Declaration
Swift
public init(bundle: Bundle = .main)Parameters
bundleA
Bundleobject associated with your app or target. If you don’t provide a bundle, then theBundle.mainit will be used by default. -
Creates and returns a new
BundleInfoVersioninginstance for a givenBundleobject and a customStorageimplementation.The
BundeInfoVersioningframework comes with a build-in storage system, implemented on top ofUserDefaults.However, if this doesn’t fit the apps needs, you can implement a custom key-value storage by conforming to the
Storageprotocol.import BundleInfoVersioning class MyStorage: Storage { func set<T>(value: T?, for key: String) { UserDefaults.standard.set(value, forKey: key) } func getValue<T>(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() }Declaration
Swift
public init(bundle: Bundle = .main, storage: Storage)Parameters
bundleA
Bundleobject associated with your app or target. If you don’t provide a bunlde,Bundle.mainit will be used.storageA
Storageobject with a custom implementation for storing theinfo.plistchanges. -
Checks for changes in your app or target
info.plistfile.Check for
CFBundleVersionupdates 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) } }Note
Thecallbackwill not be called if the providedBundleobject doesn’t have an associatedinfo.plistfile. Also, thecallbackwill not be called if the provied key path is not valid.Declaration
Swift
public func check<T>(forKeyPath keyPath: String, callback: (_ storedValue: T?, _ currentValue: T?) -> Void) where T : ComparableParameters
keyPathA valid key path from your app or target
info.plistfile.callbackThe
callbackclosure that is called with thestoredValuesand thecurrentValuefor the given key path. Thecallbackis called when thestoredValueandcurrentValueare different.storedValueThe stored value for a given key path. First time this will be
nil.currentValueThe current value from the
info.plistfile for the given key path.
BundleInfoVersioning Class Reference