我尝试在应用商店触发新版本,然后我将用户重定向到应用商店。然后在里面我更新应用程序。完成下载后,我点击应用程序商店内打开然后我的应用程序将打开一个闪屏,然后它将自动关闭。我没有得到任何崩溃日志。这是我的代码。
DispatchQueue.global().async {
do {
let update = try self.needsUpdate()
print("update",update)
DispatchQueue.main.async {
if update{
self.popupUpdateDialogue();
}
}
} catch {
print(error)
}
}
func popupUpdateDialogue(){
var versionInfo = ""
do {
versionInfo = try self.getAppStoreVersion()
}catch {
print(error)
}
let alertMessage = "Please update this app to version "+versionInfo;
let alert = UIAlertController(title: "New Version Available", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
let okBtn = UIAlertAction(title: "Update", style: .default, handler: {(_ action: UIAlertAction) -> Void in
if let url = URL(string: "itms-apps://itunes.apple.com/sg/app/myApp/idxxxx"),
UIApplication.shared.canOpenURL(url){
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
})
let noBtn = UIAlertAction(title:"Skip this Version" , style: .destructive, handler: {(_ action: UIAlertAction) -> Void in
})
alert.addAction(okBtn)
alert.addAction(noBtn)
self.present(alert, animated: true, completion: nil)
}
func needsUpdate() -> Bool {
let infoDictionary = Bundle.main.infoDictionary
let appID = infoDictionary!["CFBundleIdentifier"] as! String
let url = URL(string: "http://itunes.apple.com/sg/lookup?bundleId=\(appID)")
let data = try? Data(contentsOf: url!)
let lookup = (try? JSONSerialization.jsonObject(with: data! , options: [])) as? [String: Any]
if let resultCount = lookup!["resultCount"] as? Int, resultCount == 1 {
if let results = lookup!["results"] as? [[String:Any]] {
if let appStoreVersion = results[0]["version"] as? String{
let currentVersion = infoDictionary!["CFBundleShortVersionString"] as? String
if !(appStoreVersion == currentVersion) {
print("Need to update [\(appStoreVersion) != \(currentVersion)]")
return true
}
}
}
}
return false
}
我真的不知道为什么该应用会自动终止/关闭。我还检查了此链接App Crash when after updating,https://stackoverflow.com/questions/17795920/ios-app-goes-crash-on-startup-after-updating-from-the-app-store,https://stackoverflow.com/questions/15409323/ios-app-cannot-be-opened-after-update但仍无法解决此问题。