- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
completionHandler();
NSLog(@"userInfo--%@",response.notification.request.content.userInfo);
// 获取通知中心的所有的Categories
[center getNotificationCategoriesWithCompletionHandler:^(NSSet<UNNotificationCategory *> * _Nonnull categories) {
for (UNNotificationCategory *category in categories) {
if ([category.identifier isEqualToString:@"my_category"] && [response.notification.request.content.categoryIdentifier isEqualToString:@"my_category"]) {
for (UNNotificationAction *textAction in category.actions) {
if ([textAction.identifier isEqualToString:@"my_text"]) {
UNTextInputNotificationAction *text = (UNTextInputNotificationAction *)textAction;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:text.textInputButtonTitle preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
}
}
}
}
}];
}