我已经完成了以下代码来显示操作按钮,而通知使用一个信号。但是当应用程序被杀死时,通知不会到来。它在后台/前台模式下正常工作。但是,当应用程序不在托盘中时,甚至通知也会停止。没有操作按钮,它工作得很好。
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if( !error ) {
[[UIApplication sharedApplication] registerForRemoteNotifications];
NSLog( @"Push registration success." );
} else {
NSLog( @"Push registration FAILED" );
}];
UNNotificationCategory *modifyCategory = [UNNotificationCategory categoryWithIdentifier:CYLInviteCategoryIdentifier actions:@[] intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];
UNNotificationAction* snoozeAction = [UNNotificationAction
actionWithIdentifier:@"ACCEPT_ACTION"
title:@"Accept"
options:UNNotificationActionOptionForeground];
UNNotificationAction* stopAction = [UNNotificationAction
actionWithIdentifier:@"DECLINE_ACTION"
title:@"Decline"
options:UNNotificationActionOptionDestructive];
UNNotificationCategory* actionCategory = [UNNotificationCategory
categoryWithIdentifier:@"INCOMING_CALL"
actions:@[snoozeAction, stopAction]
intentIdentifiers:@[]
options:UNNotificationCategoryOptionNone];
[center setNotificationCategories:[NSSet setWithObjects: modifyCategory, actionCategory,
nil]];