我需要从锁定屏幕获取本地通知数据,否则应用被杀死。有没有一种方法可以检测到它,或者有任何在显示后触发的处理程序? 我尝试使用当前的UNUserNotificationCenter和UNUserNotificationCenter didReceive,但仍然无法正常工作。
答案 0 :(得分:1)
response.notification.request.content.userInfo包含通知数据
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
completionHandler()
guard let bodyText = response.notification.request.content.userInfo["body"] as? String else {return}
}
答案 1 :(得分:0)
func application(_ application: UIApplication, didReceiveRemoteNotification
userInfo: [AnyHashable : Any])
{
if application.applicationState == .inactive || application.applicationState == .background
{
//opened from a push notification when the app was on background
}
}