0

我正在尝试为 CloudKit 通知创建订阅,但我似乎无法正确使用谓词。简单通知,只显示一个比较谓词,因此有效负载配置正确,但如果我使谓词更复杂一点,它不会收到任何通知。我需要订阅多个记录更改,但我必须一一进行。我想要的是能够使用 IN 或 OR 进行一次订阅,但它似乎不起作用。

工作谓词

let predicate = NSPredicate(format: "recordID == %@", recordID1)

非工作谓词

let recordIDs = [recordID1, recordID2, recordID3, recordID4]
let predicate1 = NSPredicate(format: "recordID IN %@", recordIDs)
let predicate2 = NSPredicate(format: "NOT recordID IN %@", recordIDs)

var predicate3 = NSPredicate(format: "recordID != %@", recordID1)
for id in recordIDs.filter {$0 != recordID1} {
    predicate3 = NSCompoundPredicate(andPredicateWith: [predicate, NSPredicate(format: "recordID != %@", id)])
}

我正在使用 CKQuery CloudKit 指南(https://developer.apple.com/reference/cloudkit/ckquery)作为参考。订阅谓词实现不同还是我只是创建了错误的谓词?顺便说一句,所有谓词都编译,在断点上它们正确显示,代码中没有错误,应用程序在任何时候都不会崩溃,我已经验证了订阅实际上是在服务器上并且我使用了谓词'已经指定。无论是在设备上还是在服务器上更改记录都没有关系,更复杂的谓词似乎永远不会匹配任何东西。

为了完整起见,这里是使用第一个谓词但不是其余部分可以完美运行的订阅代码的其余部分,

let subscription = CKSubscription(recordType: "Avatar", predicate: predicate, options: CKSubscriptionOptions.FiresOnRecordUpdate)
let notificationInfo = CKNotificationInfo()
notificationInfo.shouldSendContentAvailable = true
subscription.notificationInfo = notificationInfo

任何帮助是极大的赞赏。

4

0 回答 0