针对CKReference的CloudKit预订通知未按预期工作

我试图设置一个CKSubscription的logging,其中包含一个CKReference字段的字段给用户。 但是,无论何时创buildlogging,都会忽略compoundPredicate的这一部分,并且通知永远不会到来。 在CKSubscription的谓词中使用CKReference有什么不同吗? 我进入仪表板input一个新的logging下我自己的用户recordID(当在模拟器中运行另一个用户),因为我相信我读了如果logging来自设备,它将不会收到通知。 任何洞察力都非常感谢,因为我已经坚持了一个星期,并找不到任何特定于此的任何事情。 我能够得到真正的types谓词通知,所以我认为我的基本设置是好的。

在仪表板中,我看到了两个testing用户的通用订阅,但没有任何用户的具体recordID(这是否重要?):

Notifications.read (equals string) Notifications.user (equals reference) 

当我执行fetchAllSubscriptionsWithCompletionHandler方法时,它会在debugging器中显示当前用户的特定recordID作为CKReference。 所以我不知道为什么不行。

这是我的代码,我首先创buildCKReference,然后用它作为我的谓词:

 var recordIDString = CKRecordID(recordName: "_a86dac8ee05f8c6ab35746bf9663d7b8") // I normally store this string in the NSUserDefaults. let userRef = CKReference(recordID: recordIDString, action: .DeleteSelf) let predicate = NSPredicate(format: "user = %@", userRef) let predicateTwo = NSPredicate(format: "read = %@", "") // I want the read field to be empty, which tells me user has not read my internal app notif. let compoundPred = NSCompoundPredicate(type: .AndPredicateType, subpredicates: [predicate, predicateTwo]) Now I set-up the subscription like this: let subscription = CKSubscription(recordType: "Notifications", predicate: compoundPred, options: .FiresOnRecordCreation) let notificationInfo = CKNotificationInfo() notificationInfo.alertBody = "Someone replied to your post" notificationInfo.shouldBadge = true subscription.notificationInfo = notificationInfo publicDB.saveSubscription(subscription, completionHandler: ({subscription, error in.....etc}) // handling this part 

我也有同样的问题,偶然发现了苹果网站上的这条信息:

创build谓词包含CKReference字段的订阅时,确保在创build谓词时使用CKRecordID对象作为字段的值。 在这种情况下使用CKRecord对象目前不工作。

当我改变我的CKQuerySubscription的谓词使用CKRecordID而不是CKReference它按预期工作。 我意识到这是一个古老的线程,但我努力寻找这个问题的答案,因为谓词似乎在CKQuery和CKQuerySubscription之间有不同的performance。

使用NSPredicate而不是NSPredicate来初始化您的订阅:

 let predicate = NSPredicate(format: "user = %@ AND read = %@", argumentArray: [userRef, ""]) let subscription = CKSubscription(recordType: "Notifications", predicate: predicate, options: .FiresOnRecordCreation) 

在我的经验与CloudKit这应该工作。