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
BundleInfoVersioning
instance for a givenBundle
object.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) }
Declaration
Swift
public init(bundle: Bundle = .main)
Parameters
bundle
A
Bundle
object associated with your app or target. If you don’t provide a bundle, then theBundle.main
it will be used by default. -
Creates and returns a new
BundleInfoVersioning
instance for a givenBundle
object and a customStorage
implementation.The
BundeInfoVersioning
framework 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
Storage
protocol.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
bundle
A
Bundle
object associated with your app or target. If you don’t provide a bunlde,Bundle.main
it will be used.storage
A
Storage
object with a custom implementation for storing theinfo.plist
changes. -
Checks for changes in your app or target
info.plist
file.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) } }
Note
Thecallback
will not be called if the providedBundle
object doesn’t have an associatedinfo.plist
file. Also, thecallback
will 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 : Comparable
Parameters
keyPath
A valid key path from your app or target
info.plist
file.callback
The
callback
closure that is called with thestoredValues
and thecurrentValue
for the given key path. Thecallback
is called when thestoredValue
andcurrentValue
are different.storedValue
The stored value for a given key path. First time this will be
nil
.currentValue
The current value from the
info.plist
file for the given key path.