Reputation: 5023
I have implemented Dynamic and Static notification in current Watch App. Even I am able to receive event in - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification
method in case of any action in Dynamic Notification.
I am using the following method to set UI in case of Dynamic Notification interface. but, this will not be the case for Static one.
- (void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler {
NSLog(@"%@",remoteNotification);
completionHandler(WKUserNotificationInterfaceTypeCustom);
}
EDIT
I have added following code in appdelegate to register for Notifications.
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
Upvotes: 1
Views: 276
Reputation: 6560
I would look into the following delegate method, with regard to your Watch App's extension delegate, for the answer to both of your questions:
- (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification
Perimeters:
NSString
) if the app is launched without tapping one of the notification buttons, or equal to the identifier you set to the notification action button if the user launches the app by tapping one of the notification's action buttons.Answer to Question 1: When the user launches the app, if implemented, this method will be called and allow you to reconfigure the app based on the user's selection.
Answer to Question 2:
The payload has the traditional structure of the Apple Notification Payload dictionary. The aps
key contains the alert
information and the badge
information. Then your custom data is attached to the overall dictionary. To access it, if you configure the payload dictionary with a key "testKey", you could access it by using remoteNotification[@"testKey"]
.
Update
According to Apple, the static notification "must not include controls, tables, maps, or other interactive elements," because it is only to be used as a fallback if the interactive notification cannot be launched in a timely manner. Source: Apple watchOS Developer Library.
Sources and/or Additional Resources:
Apple Developer: WK InterfaceController Class Reference
Apple Developer: The Remote Notification Payload
Apple Developer: Notification Essentials for watchOS
Upvotes: 1