SHBerooz
What it does?
SHBerooz makes checking for updates and notifying the user about new versions of the app easier. It also features forceUpdate mode which does not allow the user to proceed unless update their current app. The update checks are in a custom regular basis which is managed automatically.
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Installation
SHBerooz is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SHBerooz'
Configurations
Create your custom configurations and set it as SHBerooz shared instance default config in your AppDelegate
or somewhere before using SHBerooz.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Configuring SHBerooz
var config = BeroozConfigurations()
config.updateUrl = URL(string: "https://api.seeb.co/apps/shberooz/example.json")
// Title for presenting alert controller.
config.alertTitle = "SHBerooz"
// Retry button title
config.retryButtonTitle = "Retry"
// Update button title
config.updateButtonTitle = "Update"
// Cancel button title
config.cancelButtonTitle = "Cancel"
// Connection error alert message
config.connectionErrorMessage = "Cannot receive update information :/"
// Update check frequency, in days
config.checkForUpdateFrequency = 7
// set default configurations
SHBerooz.shared.config = config
return true
}
Then use the function checkForUpdates
on SHBerooz shared instance to check for update. Then use the completion handler with UpdateCheckStatus
enum to receive the result for processing.
SHBerooz.shared.checkForUpdates(withAlert: true) { (result) in
var canProceed = false
switch(result)
{
case .wrongConfigs:
print("config error")
break
case .updateCheckNotNeeded:
canProceed = true
break
case .appVersionIsCurrent:
canProceed = true
break
case .failedToCheck(let error):
print("Connection error :( \(String.init(describing: error))")
break
case .failedToParse(let error):
print("Parsing error :( \(String.init(describing: error))")
break
case .newVersionAvailable(let updateObject, let proceed):
canProceed = proceed
break
}
// now we proceed if the app is updated OR the needed update is not forced.
if canProceed {
// Your app can proceed.
}else {
// Show some errors.
}
}
}
Author
Shahin Katebi, [email protected]
https://www.linkedin.com/in/katebi/
License
SHBerooz is available under the MIT license. See the LICENSE file for more info.