Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
687 views
in Technique[技术] by (71.8m points)

objective c - UIAlertController:supportedInterfaceOrientations was invoked recursively

When two alert present one by one, i means one alert present and over them another alert presenting and app crashing. I have used UIAlertController to display alert. App crashing only in iOS 9 device.

Please help me at this point.

question from:https://stackoverflow.com/questions/31406820/uialertcontrollersupportedinterfaceorientations-was-invoked-recursively

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is a bug in iOS 9 that it failed to retrieve the supportedInterfaceOrientations for UIAlertController. And it seems it dropped to an infinite recursion loop in looking for the supportedInterfaceOrientations for UIAlertController (e.g., it tracks back to UIAlertControler -> UIViewController -> UINavigationController -> UITabBarController -> UIAlertController -> ...), while the call to UIAlertController:supportedInterfaceOrientations actually is not implemented/overridden in the source code.

In my solution, I just added the following piece of code:

extension UIAlertController {     
    public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.Portrait
    }
    public override func shouldAutorotate() -> Bool {
        return false
    }
}

Then UIAlertController will directly return the supported orientation value without infinite loop. Hope it helps.

Edit: Swift 3.0.1

extension UIAlertController {
    open override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.portrait
    }  
    open override var shouldAutorotate: Bool {
        return false
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...