swift – UIAlertView正在iOS 7上崩溃应用程序

我刚刚在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))

我用这个方法实际解决一个objC帮助器类:

+ (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
}

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...