Merge pull request #6 from nsagora/swiftui-issue Add usage sample for swift-ui projects
Merge pull request #6 from nsagora/swiftui-issue
Add usage sample for swift-ui projects
BundeInfoVersioning is a lightweight package that allows you to observe changes in the Info.plist file when there is an app update.
BundeInfoVersioning
Info.plist
You can use the Swift Package Manager to install BundeInfoVersioning by adding it to your Package.swift file:
Package.swift
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.
Sources
Check for CFBundleShortVersionString updates and show a What’s new like screen each time the user updates the app:
CFBundleShortVersionString
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:
CFBundleVersion
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.
NSAgora/DatabaseVersion
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.
Bundle
By default it is initialized with the .main bundle.
.main
The BundeInfoVersioning framework comes with a build-in storage system, implemented on top of UserDefaults.
UserDefaults
However, if it doesn’t fit the apps needs, you can implement a custom storage by conforming to the Storage protocol.
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.
LICENSE
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]
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
Bundle Info Versioning
Introduction
BundeInfoVersioning
is a lightweight package that allows you to observe changes in theInfo.plist
file when there is an app update.Requirements
Installation
Swift Package Manager
You can use the Swift Package Manager to install
BundeInfoVersioning
by adding it to yourPackage.swift
file: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:Check for
CFBundleVersion
updates and track in the analytics when the app is installed or updated:Check for a custom key path (e.g.
NSAgora/DatabaseVersion
) updates and execute the migration code for the data base.Advanced usage
The
BundeInfoVersioning
class allows to specify theBundle
on which will be observing theInfo.plist
changes.By default it is initialized with the
.main
bundle.Specify bundle
The
BundeInfoVersioning
framework comes with a build-in storage system, implemented on top ofUserDefaults
.However, if it doesn’t fit the apps needs, you can implement a custom storage by conforming to the
Storage
protocol.Custom storage
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]