BundeInfoVersioning
is a lightweight package that allows you to observe changes in the Info.plist
file when there is an app update.
- iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
- Xcode 11.0+
- Swift 5.1+
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),
]
)
To manually add this library in your project, just drag the Sources
folder into the project tree.
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()
}
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
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
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()
}
We would love you for the contribution to BundleInfoVersioning, check the LICENSE
file for more info.
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.