UIAlertView is crashing app on iOS 7

前端 未结 2 1197
别那么骄傲
别那么骄傲 2020-12-20 10:14

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

相关标签:
2条回答
  • 2020-12-20 10:37

    Here is my drag and drop swift solution:

    //Alerts change in iOS8, this method is to cover iOS7 devices
    func CozAlert(title: String, message: String, action: String, sender: UIViewController){
    
        if respondsToSelector("UIAlertController"){
            var alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
            alert.addAction(UIAlertAction(title: action, style: UIAlertActionStyle.Default, handler:nil))
            sender.presentViewController(alert, animated: true, completion: nil)
        }
        else {
            var alert = UIAlertView(title: title, message: message, delegate: sender, cancelButtonTitle:action)
            alert.show()
        }
    }
    

    Call like this:

    CozAlert("reportTitle", message: "reportText", action: "reportButton", sender: self)
    

    Beware this is only for the most basic alerts, you might need additional code for advanced stuff.

    0 讨论(0)
  • 2020-12-20 10:44

    I had the same problem in the relese build. It seems an internal bug of the swift compiler (using Xcode 6.0.1 (6A317) )

    I solved actually with a objC helper class with this method:

    + (BOOL) checkIfClassExists:(NSString *)className {
        id c = objc_getClass([className cStringUsingEncoding:NSASCIIStringEncoding]);
        if (c != nil) {
            return YES;
        } else {
            return NO;
        }
    }
    

    called in my swift code with a bridge header

    if ObjCFix.checkIfClassExists("UIAlertController") {
        //iOS 8 code here
    } else {
        //iOS 7 code here
    }
    
    0 讨论(0)
提交回复
热议问题