记录中特定字段的cloudkit通知

问题描述 投票:2回答:1

我有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
          }

问题是,此记录中有多个字段。我只想在一个特定字段发生变化时提醒用户。

创建订阅时,有没有办法设置搜索谓词以检测特定字段中的更改?我阅读了各种谓词文档,但没有看到这个具体提到。

或者,在收到通知时,有没有办法查看哪些字段已更改?在didReceiveRemoteNotification我试过:

 CKQueryNotification *queryNotification = [CKQueryNotification notificationFromRemoteNotificationDictionary:userInfo]; 

但是queryNotification.recordFields是空的。

在最糟糕的情况下,我已经考虑将特定字段分解为它自己的记录,但是后来我有通过常见的GUID维护更多记录的开销。我希望保持这个更紧凑。

ios apple-push-notifications nspredicate cloudkit cknotification
1个回答
1
投票

你的问题有点老化,所以也许你已经想到了这一点,但使用desiredKeys属性可能会有所帮助:https://developer.apple.com/documentation/cloudkit/cknotificationinfo/1514931-desiredkeys

如果这些通知是静默推送,您可以查看有效负载以查看某些密钥是否已更改并让您的应用程序做出相应的反应。

如果这些是推送(对用户可见)通知,我认为您不能根据密钥更改本身进行推送。你可以在你的NSPredicate上设置CKQuerySubscription,如果你正在测试值的变化(它是否等于或等于,等等),但我不确定它是否因任何变化而被触发。

© www.soinside.com 2019 - 2024. All rights reserved.