Reputation: 1137
I'm looking to customize the dismiss button and the button I sent via the PushNotificationPayload.apns via "WatchKit Simulator Actions" in my dynamic notification. Can someone please show me what I am overlooking?
Also, how do I handle the functionality of pressing the button? Ideally I would like to send information back to the parent app.
Upvotes: 0
Views: 2389
Reputation: 389
in complement to lvp's answer i've detailed the procedure to register the new category in you're iphone parent app there : (needs for production apns)
How to Handle Action Buttons in Push Notifications
****EDIT****
in resume :
From the a Server APNS you have to send a category (for me Respond):
{"aps":{"alert":"bla","category":"respond","badge":2}}
Register for that Category in you're parent's app appDelegate :
- (void)registerSettingsAndCategories {
// Create a mutable set to store the category definitions.
NSMutableSet* categories = [NSMutableSet set];
// Define the actions for a meeting invite notification.
UIMutableUserNotificationAction* acceptAction = [[UIMutableUserNotificationAction alloc] init];
acceptAction.title = NSLocalizedString(@"Repondre", @"Repondre commentaire");
acceptAction.identifier = @"respond";
acceptAction.activationMode = UIUserNotificationActivationModeForeground; //UIUserNotificationActivationModeBackground if no need in foreground.
acceptAction.authenticationRequired = NO;
// Create the category object and add it to the set.
UIMutableUserNotificationCategory* inviteCategory = [[UIMutableUserNotificationCategory alloc] init];
[inviteCategory setActions:@[acceptAction]
forContext:UIUserNotificationActionContextDefault];
inviteCategory.identifier = @"respond";
[categories addObject:inviteCategory];
// Configure other actions and categories and add them to the set...
UIUserNotificationSettings* settings = [UIUserNotificationSettings settingsForTypes:
(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound)
categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];}
And handle this in your WatchKit Extention :
- (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification{
if ([identifier isEqualToString:@"respond"]) {
//Do stuff Here to handle action...
}}
Upvotes: 3
Reputation: 2088
Answering first question: it's not possible to customize dismiss button nor buttons added via PushNotificationPayload.apns. They are provided by system.
Answering second question: In your PushNotificationPayload.apns you have something like this:
"WatchKit Simulator Actions": [
{
"title": "Button 1",
"identifier": "button1Action",
},
{
"title": "Button 2",
"identifier": "button2Action",
}
],
Then in your main interface controller, implement this method
- (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification
{
// Detect button identifier, decide which method to run
}
However, remember that on actual device if you plan to use LocalNotification you need to implement
- (void)handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)localNotification;
Hope this helps.
Edit
And if you want to send data to iPhone app use
openParentApplication
method of InterfaceController class.
Upvotes: 3