Ios 未调用userNotificationCenter未接收NotificationResponse

Ios 未调用userNotificationCenter未接收NotificationResponse,ios,unnotificationrequest,Ios,Unnotificationrequest,我已经声明我的类也符合UnuseNotificationCenterDelegate,我将所述类声明为didFinishLaunchingWithOptions中的当前UNNotificationCenter委托 但是,无论我做什么,我都无法接收对自定义操作的方法userNotificationCenter didReceiveNotificationResponse的回调。代码附在下面 有效的东西: -能够很好地看到通知 -能够点击按钮启动应用程序,确实可以启动应用程序 不符合以下条件的事项:

我已经声明我的类也符合UnuseNotificationCenterDelegate,我将所述类声明为didFinishLaunchingWithOptions中的当前UNNotificationCenter委托

但是,无论我做什么,我都无法接收对自定义操作的方法userNotificationCenter didReceiveNotificationResponse的回调。代码附在下面

有效的东西: -能够很好地看到通知 -能够点击按钮启动应用程序,确实可以启动应用程序

不符合以下条件的事项: -能够单击按钮测试,该按钮只会取消通知,而不会调用方法userNotificationCenter didReceiveNotificationResponse

UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter];

NSDate *now = [[NSDate alloc]init];
NSDate *inABit = [now dateByAddingTimeInterval:10];

NSDateComponents *components = [[NSCalendar currentCalendar] components: NSCalendarUnitSecond | NSCalendarUnitMinute | NSCalendarUnitHour | NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:inABit];

UNCalendarNotificationTrigger *calendarTrigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:NO];

//register category

UNNotificationAction *test = [UNNotificationAction actionWithIdentifier:@"test" title:@"Test" options:@[]];
UNNotificationAction *launchApp = [UNNotificationAction actionWithIdentifier:@"launchApp" title:@"Launch App" options:UNNotificationActionOptionForeground];
UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@"notification" actions:@[test, launchApp] intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];
[notificationCenter setNotificationCategories:[NSSet setWithObject:category]];

//schedule notification
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc]init];
[content setTitle:@"Hello"];
[content setBody:@"Hello notification!"];
[content setCategoryIdentifier:@"notification"];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"request" content:content trigger:calendarTrigger];

[notificationCenter addNotificationRequest:request withCompletionHandler:
 ^(NSError *error){
     if(error!=nil)
     {
         NSLog(@"There was an error adding a notification request.");
     }
 }];

当然,我已经实现了这个方法(userNotificationCenter didReceiveNotificationResponse),我不想在这里显示它,因为它占用了空间。该方法执行NSLog并在10秒后安排另一个通知。所有这些都不会发生,因为没有调用该方法。

这是一个iOS错误。它已在iOS 10.1中修复,这要感谢您可能忘记将其放在.m文件中:
self.userNotificationCenter.delegate=self希望有帮助:)