我有以下代码:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let queryNotification = CKQueryNotification(fromRemoteNotificationDictionary: userInfo)
let notification = Notification(name: NSNotification.Name("Name"), object: nil, userInfo: ["Key": queryNotification])
NotificationCenter.default.post(notification)
}
但是,我被告知这不是接收远程通知的正确方法。相反,我被指示使用以下委托方法。我不知道如何使用这种方法来做我上面做的事情。有人请帮忙。
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { }
答案 0 :(得分:2)
我认为您尝试做的事情是这样的:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// Extrapolate userInfo
let userInfo = response.notification.request.content.userInfo
let queryNotification = CKQueryNotification(fromRemoteNotificationDictionary: userInfo)
let notification = Notification(name: NSNotification.Name("Name"), object: nil, userInfo: ["Key": queryNotification])
NotificationCenter.default.post(notification)
completionHandler()
}