我刚刚在App Store上发布了我的应用程序,但我刚收到电子邮件,并告知崩溃存在问题.
问题在于警报视图会在我们的应用程序出现时崩溃(仅在iOS 7中).我有一些应该修复此问题的代码,但它似乎不适用于某些版本的iOS 7.
这是我目前的代码:
@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() } }
我该怎么做才能确保我的应用程序不会在任何版本的iOS 7或8上崩溃?
我在修复版本中遇到了同样的问题.
这似乎是swift编译器的内部错误(使用Xcode 6.0.1(6A317))
原文链接:https://www.f2er.com/swift/319963.html这似乎是swift编译器的内部错误(使用Xcode 6.0.1(6A317))
+ (BOOL) checkIfClassExists:(NSString *)className { id c = objc_getClass([className cStringUsingEncoding:NSASCIIStringEncoding]); if (c != nil) { return YES; } else { return NO; } }
用我的swift代码调用了一个桥头
if ObjCFix.checkIfClassExists("UIAlertController") { //iOS 8 code here } else { //iOS 7 code here }