UIAlertControllerAnimatedTransitioning内部崩溃

时间:2018-03-21 20:46:32

标签: ios uialertcontroller

我收到来自以下方法抛出异常的崩溃报告:

import io.realm.RealmObject;

/**
 * Created by MateusPC1 on 19/03/2018.
 */

public class dbRealm extends RealmObject{

    private String points;

    public String getPoints() {
        return points;
    }

    void setPoints(String points) {
        this.points = points;
    }
}

发生在-[_UIAlertControllerAnimatedTransitioning _animateTransition:completionBlock:]

崩溃中包含的唯一信息是:

_UIAlertControllerTransitioning.m:146

完整的调用堆栈如下所示:

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

1 个答案:

答案 0 :(得分:1)

this post开始,_UIAlertControllerTransition.m该行上断言的实际异常描述为:

  

UIAlertController在转换期间应具有视觉风格

似乎有几个原因会发生这种情况:

1。您尝试显示警报的窗口未配置正确的大小

根据此this post,确保您等到application:didFinishLaunchingWithOptions:创建窗口。

而不是在你的app委托中使用这样的东西:

class AppDelegate: UIResponder, UIApplicationDelegate {
    // BAD DON'T DO THIS
    var window: UIWindow? = UIWindow(frame: UIScreen.main.bounds)
}

确保按照以下方式创建窗口:

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    open func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        self.window = UIWindow(frame: UIScreen.main.bounds)
        // Setup rootViewController and whatever other properties
        self.window?.makeKeyAndVisible()
   }
}

2。您正尝试在外部屏幕上显示提醒(通过HDMI或Airplay)

我通过首先检查视图控制器的窗口是否是关键窗口来避免这种情况:

guard let window = self.view?.window else {
    print("Attempt to present alert on view controller without a window")
    return
}

guard window.isKeyWindow else {
    print("Attempt to present alert on window that is not the key window")
    return
}

// Present alert