Я решил это сам с помощью следующего кода:
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
UNAuthorizationOptions authOptions =
UNAuthorizationOptionAlert
| UNAuthorizationOptionSound
| UNAuthorizationOptionBadge;
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
UNNotificationAction *accept = [UNNotificationAction actionWithIdentifier:kAcceptIdentifier
title:NSLocalizedString(@"Accept", nil)
options:UNNotificationActionOptionForeground];
UNNotificationAction *reject = [UNNotificationAction actionWithIdentifier:kRejectIdentifier
title:NSLocalizedString(@"Reject", nil)
options:UNNotificationActionOptionForeground];
NSArray *buttons = @[ accept, reject ];
// create a category for action
UNNotificationCategory *buttonsAction = [UNNotificationCategory categoryWithIdentifier:@"Chat_Request"
actions:buttons
intentIdentifiers:@[]
options:UNNotificationCategoryOptionCustomDismissAction];
NSSet *categories = [NSSet setWithObjects:buttonsAction, nil];
// registration
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:categories];
}];
Убедитесь, что ваша полезная нагрузка должна содержать ключ «категория» с тем же идентификатором, что и ваш код в вашем коде.Например:
{"aps":{"alert":"Testing2","badge":1,"sound":"default","category":"Chat_Request"}}