我试过这个建议
@Kymer
并核实了电话
contentHandler
在等待了一段时间(例如3秒)后,为我解决了这个问题,例如。
// UNUserNotificationCenter *notificationCenter
// NSArray(NSString *) *matchingIdentifiers;
// UNNotificationContent *content;
if (matchingIdentifiers.count > 0) {
NSLog(@"NotificationService: Matching notification identifiers to remove: %@.", matchingIdentifiers);
[notificationCenter removeDeliveredNotificationsWithIdentifiers:matchingIdentifiers];
// Note: dispatch delay is in nanoseconds... :(
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3000000000), dispatch_get_main_queue(), ^{
NSLog(@"Replacing content after 3 seconds.");
self.contentHandler(content);
});
}
所以我认为这意味着这是一个时间问题,iOS在
内容处理程序
notificationCenter
编辑:
虽然问题不在于如何处理,但评论部分带来了对任意时间延迟的担忧。在我的测试中,在另一个循环上发布回调就足够了。
dispatch_async(dispatch_get_main_queue(), ^{
contentHandler(content);
});