1

I try trigger new version available at app store, then i will redirect user to app store. Then inside there i update the app. After finish download, i click open inside app store then my app will open a splash screen then it will auto close. I not get any crash log. This is my code.

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
}

I really dont know why the app will auto terminate/close. I also already checked on this link 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 but still not get what solution for this issue.

MAS. John
  • 582
  • 6
  • 22
  • Running same version of application from xcode doesn't produce this crash? Does your xcode show any of those crash reports? For starters I would implement one of the crash reporting frameworks so you are up to date with crashes in the future. When you have crash log everything is easier. – ZassX Mar 20 '18 at 15:48
  • Application from xcode is 1.6 .. and from app store 1.7 .. both can run smoothly. I directly run app version 1.6 from xcode, working without crash. From app store also same, when directly download and install, working fine. I archive the app version 1.6 from xcode and distribute for testing, it working. But inside the app, i prompt new version from app store and update app from there , then tried open my app then it will open around 2-3 second then auto close.. – MAS. John Mar 20 '18 at 16:13
  • Crashlytic report never sent report about that. look like it not crash. – MAS. John Mar 20 '18 at 16:14
  • Huh strange. But Crashlytics should report it in case the error happens. Are you sure you configured it right? Try performing manual crash just to make sure it is working. – ZassX Mar 20 '18 at 16:17
  • ya totally sure Crashlytics already right because i got report for other crash . – MAS. John Mar 20 '18 at 16:54

0 Answers0