大佬教程收集整理的这篇文章主要介绍了ios – CKFetchNotificationChangesOperation返回旧通知,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
__block NSMutableArray *notificationIds = [NSMutableArray new]; CKFetchNotificationChangesOperation *operation = [[CKFetchNotificationChangesOperation alloc] initWithPrevIoUsServerChangeToken:self.serverChangeToken]; operation.notificationChangedBlock = ^(CKNotification *notification) { [notificationIds addObject:notification.notificationID]; [self processRemoteNotification:notification withCompletionHandler:completionHandler]; }; __weak CKFetchNotificationChangesOperation *operationLocal = operation; operation.fetchNotificationChangesCompletionBlock = ^(CKServerChangeToken *serverChangeToken,NSError *operationError) { if (operationError) { NSLog(@"Unable to fetch queued notifications: %@",operationError); } else { self.serverChangeToken = serverChangeToken; completionHandler(UIBACkgroundFetchResultNewData); // Mark the processed notifications as read so they're not delivered again if the token gets reset. CKMarkNotificationsReadoperation *markReadoperation = [[CKMarkNotificationsReadoperation alloc] initWithNotificationIDsToMarkRead:[notificationIds copy]]; [notificationIds removeAllObjects]; markReadoperation.markNotificationsReadCoR_213_11845@pletionBlock = ^(NSArray *notificationIDsmarkedRead,NSError *operationError) { if (operationError) { NSLog(@"Unable to mark notifications read: %@",operationError); } else { NSLog(@"%lu notifications marked read.",(unsigned long)[notificationIDsmarkedRead count]); } }; [[CKContainer defaultContainer] addoperation:markReadoperation]; if (operationLocal.moreComing) { NSLog(@"Fetching more"); [self checkNotificationQueueWithCompletionHandler:completionHandler]; } } }; [[CKContainer defaultContainer] addoperation:operation];
据我所知,标记通知读取将使其不会在将来的队列提取中显示,即使服务器更改标记重置为nil.相反,当每个fetch只有1或2个新的时,我会在每次获取中获得很多旧的通知.我可以从notificationType标志中检测到旧的,但我担心它们会出现.我在某处错过了一步吗?
在我的代码中,我做的和你一样:也就是说,将所有的notificationID添加到一个数组并在我的CKMarkNotificationsReadoperation中使用它,并且每次都返回所有通知(尽管如你所知,有一种类型的“ReadNotification”).
我更改了我的代码,以便我只向我的数组添加“新”通知,而不是“ReadNotification”项,并发送它们.修好了.
似乎将通知发送回服务器以标记为已读,即使它已被标记为已读,也会导致它再次作为“ReadNotification”返回.
我希望这可以帮助别人.
以上是大佬教程为你收集整理的ios – CKFetchNotificationChangesOperation返回旧通知全部内容,希望文章能够帮你解决ios – CKFetchNotificationChangesOperation返回旧通知所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。