didReceiveRemoteNotification中的崩溃

时间:2019-02-02 19:23:36

标签: ios swift

碰撞是发生在活的应用程序。我无法获取崩溃日志。我可以在管理器->崩溃中看到以下内容,单击该按钮将我带到下面提到的以下行。如何调试此崩溃或预防崩溃?

Crash in Organizer

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    // Crash happens here
    let tabBar:UITabBarController = self.window?.rootViewController as? UITabBarController 
}

1 个答案:

答案 0 :(得分:0)

我不明白您为什么只检查rootViewControllerUITabBarController。但是我认为,崩溃之所以发生是因为您没有致电completionHandler。尝试在方法末尾添加:

completionHandler(.noData) // or with other parameters of UIBackgroundFetchResult type.

摘自Apple文档:

  

只要处理完的通知,则必须调用处理器参数块或您的应用程序将被终止。您的应用最多有30秒的挂钟时间来处理通知并调用指定的完成处理程序块。实际上,您应该在处理完通知后立即调用处理程序块。该系统跟踪所经过的时间,用电量,并为您的应用程序的后台下载数据的成本。处理远程通知时使用显著量的功率的应用程序可以不总是早唤醒以处理未来的通知。

检查苹果documentation