Ответ 1
Я боролся с этим в течение двух часов, так вот как я делаю для кнопок уведомлений в процессе производства через реальный APNS Serv,
1) Зарегистрируйте категорию в своем приложении 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];
}
2) С вашего сервера Apns добавьте категорию (для меня "ответьте" )
{"aps":{"alert":"bla","category":"respond","badge":2}}
3) В вашем WatchKitExtention у вас есть данные, переданные в:
- (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification{
if ([identifier isEqualToString:@"respond"]) {
//Do stuff Here to handle action...
}
}
4) В приложении Parent appDelegate:
- (void) application:(UIApplication *)application
handleActionWithIdentifier:(NSString *)identifier
forRemoteNotification:(NSDictionary *)userInfo
completionHandler:(void (^)())completionHandler {
completionHandler();
}
Внимание! вам придется обрабатывать это действие также в своем приложении "Родитель" (потому что кнопка "Отклик" будет видна и на iphone при панорамировании уведомления.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {