Как обрабатывать кнопки действий в Push-уведомлениях

Работа с уведомлениями Apple Watch: -, поэтому, если я добавляю кнопку в интерфейсе уведомлений (из объекта Lib), то ошибка:

Кнопки не поддерживаются в интерфейсе уведомлений

PushNotificationPayload.apns имеет WatchKit Simulator Actions Like This:

"WatchKit Simulator Actions": 
[
    {
        "title": "View",
        "identifier": "firstButtonAction"
    }
],

и симулятор Показывает это мне

enter image description here

Теперь мой вопрос: как я могу обращаться с этой кнопкой View при отправке PushNotification с сервера,

Если файл aps содержит кнопку действия, это единственный вариант для Apple Watch,

Как отправить его с сервера в словаре уведомлений с указанным ключом?

Как изменить кнопку "Действие" Цвет BG?

Кто-нибудь, пожалуйста, дайте мне образец aps файла, который включает ActionButton для устройства the Apple Watch не для Simulator

Я просто проверю, изменив ключ WatchKit Simulator Actions на WatchKit Actions, но не показывает кнопку действия.

Как было предложено @vivekDas в ответе, я проверил, заменив в aps как:

"alert" : {
     "body" : "Acme message received from Johnny Appleseed",
     "action-loc-key" : "VIEW",
     "action" : [
        {
           "id" : "buttonTapped",
           "title" : "View"
        }
     ]
  }

но симулятор в Xcode показывает кнопку действия.

Я думаю, что это может работать на устройстве Apple Watch, это...?

Что бы вы мне посоветовали.

Ответы

Ответ 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 {