我正在尝试为包含带有用户 CKReference 的字段的记录设置 CKSubscription。但每当创建记录时,它都会忽略compoundPredicate的这一部分,并且通知永远不会出现。在 CKSubscription 的谓词中使用 CKReference 有什么不同吗?我进入仪表板在我自己的用户 recordID 下输入一条新记录(同时在模拟器中运行另一个用户),因为我相信我读到如果记录来自设备,它将不会收到通知。非常感谢任何见解,因为我已经在这个问题上坚持了一个星期,并且在网上找不到任何与此相关的内容。我能够获得真实类型谓词通知,所以我认为我的基本设置没问题。
在仪表板中,我看到两个测试用户都有一个通用订阅,但没有看到任一用户的任何特定 recordID(这重要吗?):
Notifications.read (equals string)
Notifications.user (equals reference)
当我执行 fetchAllSubscriptionsWithCompletionHandler 方法时,它确实会将此设备的当前用户的特定 recordID 显示为调试器中的 CKReference。所以我不知道为什么它不起作用。
这是我的代码,我首先创建 CKReference,然后将其用于我的谓词:
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