I have just released my app on the App Store however I have just been emailed and told that there is issues with crashing.
The issue is with Alert Views which crash my app when they are supposed to appear (only in iOS 7). I had some code in place that was supposed to fix this issue, however it doesn't seem to work in certain versions of iOS 7.
Here is my current code:
@IBAction func resetAllButton(sender : AnyObject) {
//If statement to check whether the modern style alert is available. Prior to iOS 8 it is not.
if let gotModernAlert: AnyClass = NSClassFromString("UIAlertController") {
println("UIAlertController can be instantiated")
var alert = UIAlertController(title: "Start Over", message: "Are you sure you want to start over? This will erase your budget and all transactions.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "I'm sure!", style: UIAlertActionStyle.Default, handler:{ (ACTION :UIAlertAction!)in
self.resetView()
}))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
else {
println("UIAlertController can NOT be instantiated")
var alertView = UIAlertView()
alertView.delegate = self
alertView.title = "Start Over"
alertView.message = "Are you sure you want to start over? This will erase your budget and all transactions."
alertView.addButtonWithTitle("I'm sure!")
alertView.addButtonWithTitle("Cancel")
alertView.show()
}
}
What can I do to ensure that my app doesn't crash on any version of iOS 7 or 8?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…