ios - 记录中特定字段的 cloudkit 通知

标签 ios apple-push-notifications nspredicate cloudkit cknotification

我有 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 为空。

作为最坏的情况,我考虑过将特定字段分解成它自己的记录,但是我有维护更多记录的开销,这些记录由一个公共(public) GUID 绑定(bind)在一起。我希望保持这个更紧凑。

最佳答案

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

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

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

关于ios - 记录中特定字段的 cloudkit 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40452641/

相关文章:

iphone - 解析要发送的数据的 APNS 提供程序

ios - 我的生产 ios 应用程序没有推送通知工作

ios - NSPredicate 用于一对一关系

ios - NSPredicate 搜索逗号分隔值与数组

ios - react native 侧菜单 "open on button click"

ios - 为 OpenSSL 运行 make 时出现 Clang 错误(iOS、i386、x86_64)

ios - 可以在拒绝选项选择后以编程方式调用 iOS 推送通知警报吗?

ios - Xcode-beta 更新时打不开

html - 如何在 iOS 上将数据转换为 CSV 或 HTML 格式?

swift - NSPredicate 数组中的过滤子项