iOS/Sample : UI need to be updated on Main Thread (#740)
Summary: ### iOSSample: Fix iOS Sample App crash: UI need to be updated on Main Thread ### SampleSwift: * Upgrade swift version * Fix force unwrapping * UI need to be updated on Main Thread ## Changelog Pull Request resolved: https://github.com/facebook/flipper/pull/740 Differential Revision: D19397414 Pulled By: passy fbshipit-source-id: 7af84c0fe43861aff6a18c36bf81a940baec5147
This commit is contained in:
committed by
Facebook Github Bot
parent
4530eb9235
commit
f6831e837a
@@ -23,9 +23,9 @@ class NetworkViewController: UIViewController {
|
||||
return
|
||||
}
|
||||
|
||||
let dict = try! JSONSerialization.jsonObject(with: dataUnwrapped, options: JSONSerialization.ReadingOptions.init(rawValue: 0)) as! [String: String]
|
||||
let dict = try? JSONSerialization.jsonObject(with: dataUnwrapped, options: JSONSerialization.ReadingOptions.init(rawValue: 0)) as? [String: String]
|
||||
// As sonar cannot detect print() in Logs
|
||||
NSLog("MSG-GET: \(dict["msg"] ?? "Did not find msg key in the received response")")
|
||||
NSLog("MSG-GET: \(dict?["msg"] ?? "Did not find msg key in the received response")")
|
||||
strongSelf.showAlert(message: "Received response from GET API, please check the sonar network plugin for detailed response")
|
||||
}
|
||||
dataTask.resume()
|
||||
@@ -55,9 +55,9 @@ class NetworkViewController: UIViewController {
|
||||
return
|
||||
}
|
||||
|
||||
let dict = try! JSONSerialization.jsonObject(with: dataUnwrapped, options: JSONSerialization.ReadingOptions.init(rawValue: 0)) as! [String: String]
|
||||
let dict = try? JSONSerialization.jsonObject(with: dataUnwrapped, options: JSONSerialization.ReadingOptions.init(rawValue: 0)) as? [String: String]
|
||||
// As sonar cannot detect print() in Logs
|
||||
NSLog("MSG-POST: \(dict["msg"] ?? "Did not find msg key in the received response")")
|
||||
NSLog("MSG-POST: \(dict?["msg"] ?? "Did not find msg key in the received response")")
|
||||
strongSelf.showAlert(message: "Received response from POST API, please check the sonar network plugin for detailed response")
|
||||
}
|
||||
dataTask.resume()
|
||||
@@ -85,9 +85,11 @@ class NetworkViewController: UIViewController {
|
||||
}
|
||||
|
||||
func showAlert(message: String) {
|
||||
let alertController = UIAlertController.init(title: "Flipper", message: message, preferredStyle: .alert);
|
||||
let alertAction = UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler: nil)
|
||||
alertController.addAction(alertAction)
|
||||
present(alertController, animated: true, completion: nil)
|
||||
DispatchQueue.main.async {
|
||||
let alertController = UIAlertController.init(title: "Flipper", message: message, preferredStyle: .alert);
|
||||
let alertAction = UIAlertAction(title: "Okay", style: UIAlertAction.Style.default, handler: nil)
|
||||
alertController.addAction(alertAction)
|
||||
self.present(alertController, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user