【发布时间】:2016-04-26 10:04:57
【问题描述】:
我在当前的 Watch App 中实现了动态和静态通知。即使在动态通知中发生任何操作时,我也能够在- (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification 方法中接收事件。
- 现在我担心的是,如何在点击实际打开 WatchOS 应用程序的通知视图时接收任何事件/回调?
- 如何通过点击通知以任何方式在启动应用时获取推送通知负载?
在动态通知界面的情况下,我使用以下方法来设置 UI。但是,Static 的情况并非如此。
- (void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler {
NSLog(@"%@",remoteNotification);
completionHandler(WKUserNotificationInterfaceTypeCustom);
}
编辑
我在 appdelegate 中添加了以下代码来注册通知。
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
【问题讨论】:
标签: objective-c push-notification apple-push-notifications watchkit watchos-2