我正在制作一款应用,并正在为未来做准备。例如,如果我的应用程序的第一个版本将来不适用于我的后端。有没有办法或最佳做法来停止应用程序,基本上说这个版本不再兼容继续使用你将不得不升级。
我的应用使用firebase作为后端。我想到的方法就是每次从firebase获得bool
的负载,说明这个版本的应用程序是否仍然兼容。如果false
我会在空白屏幕上发出通知,说您必须从appstore升级。我想知道是否有更好的正常方法来做这个/如果人们不这样做。
我知道这绝对不是我想做的事情,但我只是在考虑这个选项。
答案 0 :(得分:2)
您可以向Firebase数据库中添加一个名为version的属性,并在那里添加应用程序正常工作的最低版本号,然后直接从AppDelegate检查应用程序的版本。它具有直接使用Firebase的优势,不需要其他框架。
您的Firebase树应如下所示:
YourApp-
- version: 1.5
- otherDataFromYourApp
然后你可以在AppDelegate中从数据库中检索版本号,并将其与最低版本进行比较:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
// get the current version of your app
let versionObject: AnyObject? = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as AnyObject?
let version = Float(versionObject as! String)!
// get the minimum version from Firebase
var minimumVersion = Float()
let ref = FIRDatabase.database().reference()
ref.child("version").observe(FIRDataEventType.value, with: { snap in
print(snap.value!)
minimumVersion = snap.value! as! Float
// compare the versions
if minimumVersion > version{
print("this is not a valid version")
self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MustUpdateViewController")
}
})
return true
}
然后,您所要做的就是创建一个新的ViewController,其故事板ID为 MustUpdateViewController ,根据您的要求进行设计,每次最小的应用程序版本更改,您需要更改Firebase版本的值。故事板中的示例:
这就是你需要做的,只需几行代码和一些设计在Storyboard中......
希望它有所帮助!
答案 1 :(得分:0)
有一个名为Harpy的开源库可以为您完成此任务!它提供了在启动时,每天或每周检查更新的功能,并使用iTunes进行检查,因此配置非常简单。
配置步骤:
在Appdelegate.m didFinishLaunchingWithOptions
方法中添加以下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Present Window before calling Harpy
[self.window makeKeyAndVisible];
// Set the UIViewController that will present an instance of UIAlertController
[[Harpy sharedInstance] setPresentingViewController:_window.rootViewController];
// Optional Set the Delegate to track what a user clicked on, or to use a custom UI to present your message.
[[Harpy sharedInstance] setDelegate:self];
// Optional
[[Harpy sharedInstance] setAlertControllerTintColor:@"<#alert_controller_tint_color#>"];
//Optional
[[Harpy sharedInstance] setAppName:@"<#app_name#>"];
/* Optional Set the Alert Type for your app
By default, Harpy is configured to use HarpyAlertTypeOption */
[[Harpy sharedInstance] setAlertType:<#alert_type#>];
/* Optional If your application is not available in the U.S. App Store, you must specify the two-letter
country code for the region in which your applicaiton is available. */
[[Harpy sharedInstance] setCountryCode:@"<#country_code#>"];
/* Optional Overrides system language to predefined language.
Please use the HarpyLanguage constants defined in Harpy.h. */
[[Harpy sharedInstance] setForceLanguageLocalization:<#HarpyLanguageConstant#>];
// Perform check for new version of your app
[[Harpy sharedInstance] checkVersion];
}
DONE !