我有 cloudkit 通知工作。当有人更改记录时,会通知订阅者。我的订阅定义如下所示:
NSPredicate *searchConditions = [NSPredicate predicateWithFormat:@"%K = %@", CLOUDKIT_PUBLIC_ID_GUID, theCloudGUID];
int subscriptionOptions = CKSubscriptionOptionsFiresOnRecordUpdate | CKSubscriptionOptionsFiresOnRecordDeletion;
CKSubscription *publicSubscription = [[CKSubscription alloc] initWithRecordType:CLOUDKIT_RECORDNAME_PUBLIC_ID
predicate:searchConditions
options:subscriptionOptions];
CKNotificationInfo *notificationInfo = [CKNotificationInfo new];
notificationInfo.alertLocalizationKey = CLOUDKIT_NOTIFICATION_PUBLIC;
notificationInfo.shouldBadge = NO;
notificationInfo.alertBody = CLOUDKIT_NOTIFICATIONBODY_PUBLIC;
publicSubscription.notificationInfo = notificationInfo;
[publicDatabase saveSubscription:publicSubscription completionHandler:^(CKSubscription * _Nullable subscription, NSError * _Nullable error)
{
//error handling
}
问题是,该记录中有多个字段。我只想在一个特定字段发生变化时提醒订阅者。
创建订阅时,有没有办法设置搜索谓词来检测特定字段的变化?我通读了各种 Predicate 文档,但没有看到特别提到这一点。
或者,在收到通知时,有没有办法查看哪些字段发生了变化?在didReceiveRemoteNotification
我尝试过:
CKQueryNotification *queryNotification = [CKQueryNotification notificationFromRemoteNotificationDictionary:userInfo];
但queryNotification.recordFields
为空。
作为最坏的情况,我考虑过将特定字段分解为它自己的记录,但是我需要维护更多由公共 GUID 捆绑在一起的记录的开销。我希望保持这个更紧凑。