Skip to content

Commit

Permalink
Fix an issue which may cause a crash due to performing layout engine …
Browse files Browse the repository at this point in the history
…on background thread
  • Loading branch information
iMac0de committed Aug 10, 2020
1 parent e92138f commit 4cea4e2
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions AppStoreVersion/AppStoreVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,23 @@ open class AppStoreVersion {
if error != nil {
NSLog("AppStoreVersion (%@): %@", AppStoreVersion.version, error!.localizedDescription)
} else if !upToDate {
let alertController = UIAlertController(title: Config.Alert.title, message: String(format: Config.Alert.message, AppStoreVersion.latestVersionAvailable), preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: Config.Alert.downloadActionTitle, style: .default, handler: { (_) in
guard let storeURLString = cache?[Keys.kAppStoreURLKey] as? String, let storeURL = URL(string: storeURLString) else {
return
}
if UIApplication.shared.canOpenURL(storeURL) {
UIApplication.shared.open(storeURL, options: [:], completionHandler: nil)
}
}))
if Config.optional {
alertController.addAction(UIAlertAction(title: Config.Alert.laterActionTitle, style: .cancel, handler: { (_) in
alertController.dismiss(animated: true, completion: nil)
DispatchQueue.main.async {
let alertController = UIAlertController(title: Config.Alert.title, message: String(format: Config.Alert.message, AppStoreVersion.latestVersionAvailable), preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: Config.Alert.downloadActionTitle, style: .default, handler: { (_) in
guard let storeURLString = cache?[Keys.kAppStoreURLKey] as? String, let storeURL = URL(string: storeURLString) else {
return
}
if UIApplication.shared.canOpenURL(storeURL) {
UIApplication.shared.open(storeURL, options: [:], completionHandler: nil)
}
}))
if Config.optional {
alertController.addAction(UIAlertAction(title: Config.Alert.laterActionTitle, style: .cancel, handler: { (_) in
alertController.dismiss(animated: true, completion: nil)
}))
}
UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true, completion: nil)
}
UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true, completion: nil)
}
}
}
Expand Down

0 comments on commit 4cea4e2

Please sign in to comment.