FirebaseCheckVersion is a simple iOS Library that notifies users when a new version of your app is available. It's configurable through Firebase Remote Configuration. Please read the Configuration section to know more.
To run the example project, clone the repo, and run pod install
from the Example directory first.
An iOS Swift project and 10 minutes of your time.
FirebaseCheckVersion is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'FirebaseCheckVersion'
First of all you need, if you haven't yet, to create a Firebase Project for your iOS Application. Go to Firebase Console and create your project:
Once you created your project you need to link your iOS Application:
Now fill the bundle id with yours, download the GoogleService-Info.plist that Firebase created for your project and drag it into your xCode Project in this way:
Go now in your AppDelegate.swift file and write FirebaseApp.configure()
and FirebaseCheckVersionConfiguration.default.shared = UIApplication.shared
how first lines of your didFinishLaunchingWithOptions:
method in this way:
import Firebase
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
FirebaseCheckVersionConfiguration.default.shared = UIApplication.shared
// Override point for customization after application launch.
return true
}
Done!
Once you configured all, you need to set the version on your Firebase Project, so navigate to "Remote Config" section into Firebase and add a new property which key is iOSVersion_<yourVersionWithUnderscore>
where is your version number or your build number (depending of which method you are going to use) with underscore instead of points:
Eg.
1.0 --> 1_0
1.1 --> 1_1
10.03.9 --> 10_03_9
12 --> 12
So if your app version is 1.0 simple configure a new Remote Configuration like this:
The possible values you can give to your version are:
versionOk
which means the version is up to dateinfoUpdate
which means the version is not the last avaiable, but can be used for your applicationforceUpdate
which means the version is not the last avaiable and can NOT be used for your application
In the UIViewController you want to add the check silently you need to insert these code lines:
import CheckVersion
...
FirebaseCheckVersion.checkVersion{ result in
//check result and do what you want
}
where result
is a enum with these possible values:
versionOk
which means your version is currently okinfoUpdate
which means the version is not the last avaiable, but can be used for your applicationforceUpdate
which means the version is not the last avaiable and can NOT be used for your applicationversionUnknown
which means your version is not configured on Firebase Consoleerror
which means an error occurred
In the UIViewController you want to add the check with Alert you need to insert these code lines:
import CheckVersion
...
FirebaseCheckVersion.checkBuildWithAlert(viewController: self){ result in
//check result and do what you want
}
where result
is a Bool with value true
if your version is ok, false
otherwise.
Is possible to choose some custom library configuration like these:
import CheckVersion
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
FirebaseCheckVersionConfiguration.default.urlStore = URL(string: "itms-apps://itunes.apple.com/<myAppId>")! //where myAppID is your store application id
FirebaseCheckVersionConfiguration.default.continueOnError = false //continue in case of error (default is true)
FirebaseCheckVersionConfiguration.default.continueOnVersionUnknown = false //continue in case of version unknown (default is true)
FirebaseCheckVersionConfiguration.default.prependKey = "" //the prepend string you can insert in firebase console before (default is 'iOSVersion_')
FirebaseCheckVersionConfiguration.default.duration = TimeInterval(120) //the duration of Firebase Remote Configuration Cache (default is 60 seconds)
// Override point for customization after application launch.
return true
}
Right now the library is localized just in English, so if you want to use built-in alerts is possible to change these configurations property too:
import CheckVersion
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
FirebaseCheckVersionConfiguration.default.labelAlertError = "Si è verificato un errore generico, per favore riprova più tardi"
FirebaseCheckVersionConfiguration.default.labelButtonNotNow = "Non adesso"
FirebaseCheckVersionConfiguration.default.labelButtonUpdate = "Aggiorna"
FirebaseCheckVersionConfiguration.default.labelForceUpdate = "E' disponibile una nuova versione dell'app: per favore aggiornala adesso"
FirebaseCheckVersionConfiguration.default.labelInfoUpdate = "E' disponibile una nuova versione dell'app: se vuoi aggiornala adesso"
FirebaseCheckVersionConfiguration.default.labelAlertTitle = "Attenzione"
FirebaseCheckVersionConfiguration.default.labelButtonOk = "Ok"
// Override point for customization after application launch.
return true
}
Mario Monaco, andoma93@gmail.com
FirebaseCheckVersion is available under the MIT license. See the LICENSE file for more info.