在Apple Watch设备

时间:2016-08-01 07:07:03

标签: objective-c swift apple-push-notifications apple-watch

处理Apple Watch通知集成:: - 我无法在推送通知中获取按钮点击操作事件。

// IOS代码

1.在AppDelegate文件中创建用于集成自定义推送通知的功能。

func registerSettingsAndCategories() {

    let categories = NSMutableSet()
    let acceptAction = UIMutableUserNotificationAction()
    acceptAction.title = "View"
    acceptAction.identifier = "view"
    acceptAction.activationMode = UIUserNotificationActivationMode.Background
    acceptAction.authenticationRequired = false

    let inviteCategory = UIMutableUserNotificationCategory()
    inviteCategory.setActions([acceptAction],forContext: UIUserNotificationActionContext.Default)
    inviteCategory.identifier = "myCategory"

    categories.addObject(inviteCategory)
    // Configure other actions and categories and add them to the set...

    let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound],categories: (NSSet(array: [inviteCategory])) as? Set<UIUserNotificationCategory>)
    UIApplication.sharedApplication().registerUserNotificationSettings(settings)
}

2.在处理通知的AppDelegate文件委托方法中:

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
   print("handleActionWithIdentifier Appdel : \(userInfo)   \(identifier)")
    print(userInfo)
    completionHandler()
}

3.在Watchkit扩展目标中的NotificationController文件句柄通知方法:

override func handleActionWithIdentifier(identifier: String?, forRemoteNotification remoteNotification: [NSObject : AnyObject]) {

    print("handleActionWithIdentifier \(remoteNotification)")
    if identifier == "myCategory"{
    }
}

我知道如果我点击&#34;查看&#34;按钮然后应该调用handleActionWithIdentifier方法,但在我的情况下,handleActionWithIdentifier方法没有被调用。我在这个问题上被困了2天。 所以任何人都可以帮我解决这个问题?

0 个答案:

没有答案