【发布时间】:2018-09-27 06:43:14
【问题描述】:
应用程序在 iOS 12.0 之前的 iOS 12.0 中崩溃,它工作正常,我用谷歌搜索了它,但没有得到以下崩溃日志的任何解决方案。
由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类与键 shouldAlwaysAlertWhileAppIsForeground 的键值编码不兼容。”
let content = UNMutableNotificationContent()
//App crash on below line
content.setValue(true, forKeyPath: "shouldAlwaysAlertWhileAppIsForeground")
有人解决过此类问题吗?
【问题讨论】:
-
UNMutableNotificationContent似乎没有正式的shouldAlwaysAlertWhileAppIsForeground属性,这可能是您的应用之前意外运行。 -
嘿@Nilesh!您是否找到任何解决此问题的方法?
-
我只是在那里添加条件 if #available(iOS 12.0, *) { }else {content.setValue(true, forKeyPath: "shouldAlwaysAlertWhileAppIsForeground") }