在解雇时不会调用UNNotificationCenterDelegate

时间:2018-04-12 10:23:24

标签: delegates watchkit unusernotificationcenter usernotifications

我有一个AppleWatch应用程序,它接收远程通知。在处理我的自定义操作时,我在我的notificationCenter(_:didRecieve response:...)上收到了一个回调" a1"和默认操作。但是,没有为自定义解除操作调用此函数...

class ExtensionDelegate: NSObject, WKExtensionDelegate, UNUserNotificationCenterDelegate {

    func applicationDidFinishLaunching() {
        // Perform any final initialization of your application.
        UNUserNotificationCenter.current().delegate = self
        UNUserNotificationCenter.current().requestAuthorization(options: [UNAuthorizationOptions.alert, UNAuthorizationOptions.sound]) { (success, err) in

        }
        let a1 = UNNotificationAction(identifier: "a1", title: "Do Stuff", options: .foreground)
        let c1 = UNNotificationCategory(identifier: "c1", actions: [a1], intentIdentifiers: [], options: .customDismissAction)
        UNUserNotificationCenter.current().setNotificationCategories([c1])

            }
    }

    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
            print("Action Identifier: \(response.actionIdentifier)"
            completionHandler()
    }
}

所以我的代表似乎也在工作,而且类别......我错过了什么?

1 个答案:

答案 0 :(得分:0)

修正了它:如果您在观察上运行您的应用并将其关闭,则会调用 iOS应用的UNUserNotificationCenterDelegate notificationCenter(_:didRecieve response:...)(在我的情况下是AppDelegate)! 可能是因为当你在手表上解雇它时,它在任何地方都被解雇了......

没有找到任何资源......如果你这样做了,  请分享链接:)