#ios
getDeliveredNotificationsWithCompletionHandler:是类中的一个方法UNUserNotificationCenter,允许您检索已发送给用户但仍在通知中心可见的通知。
使用此方法的方法如下:
导入用户通知框架:
首先,确保文件顶部有必要的导入语句:
@import UserNotifications;
获取已发送的通知:
您可以调用此方法来获取已发送通知的数组:
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {
for (UNNotification *notification in notifications) {
NSLog(@"Delivered notification: %@", notification.request.content.title);
// You can access other properties like subtitle, body, etc.
}
}];
UNNotification,每个对象代表一个已传递的通知。