加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 05:44:11 所属栏目:百科 来源:网络整理
导读:我刚刚在App Store上发布了我的应用程序,但我刚收到电子邮件,并告知崩溃存在问题. 问题在于警报视图会在我们的应用程序出现时崩溃(仅在iOS 7中).我有一些应该修复此问题的代码,但它似乎不适用于某些版本的iOS 7. 这是我目前的代码: @IBAction func resetAll
我刚刚在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
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读