Created
November 25, 2021 18:44
-
-
Save sheerazam/294af62b5ffb8f792cec00365f50d048 to your computer and use it in GitHub Desktop.
Implementing Force Update Feature using Firebase Remote Config in iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Mark:- RemoteConfig Setup | |
extension MyAppDelegate { | |
func setupRemoteConfig(){ | |
remoteConfig = RemoteConfig.remoteConfig() | |
remoteConfig.configSettings = RemoteConfigSettings(developerModeEnabled: true)! | |
//set in app defaults | |
let defaults : [String : Any] = [ | |
ForceUpdateChecker.FORCE_UPDATE_REQUIRED : false, | |
ForceUpdateChecker.FORCE_UPDATE_CURRENT_VERSION : "1.0(1)", | |
ForceUpdateChecker.FORCE_UPDATE_STORE_URL : "https://itunes.apple.com/us/app/myapp/id12345678?ls=1&mt=8" | |
] | |
remoteConfig.setDefaults(defaults as? [String : NSObject]) | |
var expirationDuration = 60 | |
// If your app is using developer mode, expirationDuration is set to 0, so each fetch will | |
// retrieve values from the service. | |
if remoteConfig.configSettings.isDeveloperModeEnabled { | |
expirationDuration = 0 | |
} | |
remoteConfig.fetch(withExpirationDuration: TimeInterval(expirationDuration)) { [weak self] (status, error) in | |
if status == .success { | |
print("config fetch done") | |
self?.remoteConfig.activateFetched() | |
} else { | |
print("Config not fetched") | |
print("Error: \(error?.localizedDescription ?? "No error available.")") | |
} | |
} | |
} | |
} | |
extension MyAppDelegate : OnUpdateNeededListener { | |
func onUpdateNeeded(updateUrl: String) { | |
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "UpdateAppViewController") as! UpdateAppViewController | |
controller.url = updateUrl | |
if(self.appVisibleController is SplashViewController){ | |
self.appVisibleController?.present(controller, animated: false, completion: nil) | |
} else if ( !( self.appVisibleController is UpdateAppViewController ) ){ | |
self.appVisibleController?.present(controller, animated: false, completion: nil) | |
} | |
} | |
func onNoUpdateNeeded() { | |
print("onNoUpdateNeeded()") | |
if(self.appVisibleController is UpdateAppViewController){ | |
self.appVisibleController?.dismiss(animated: false, completion: nil) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment