【发布时间】:2015-04-22 01:14:54
【问题描述】:
我正在尝试为包含具有用户 CKReference 的字段的记录设置 CKSubscription。但无论何时创建记录,它都会忽略复合谓词的这一部分,并且永远不会收到通知。在 CKSubscription 的谓词中使用 CKReference 有什么不同吗?我进入仪表板以在我自己的用户 recordID 下输入新记录(在模拟器中运行另一个用户时),因为我相信我读到如果记录来自设备,它将不会收到通知。非常感谢任何见解,因为我已经坚持了一周并且无法在网上找到任何特定于此的内容。我能够获得真实类型的谓词通知,所以我认为我的基本设置还可以。
在仪表板中,我看到两个测试用户都有一个通用订阅,但没有任何一个用户的特定记录 ID(这有关系吗?):
Notifications.read (equals string)
Notifications.user (equals reference)
当我执行 fetchAllSubscriptionsWithCompletionHandler 方法时,它会在调试器中将当前用户对此设备的特定记录 ID 显示为 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
【问题讨论】:
-
我认为 CloudKit 不适用于复合谓词。我想我在某处读到过它,但找不到精确的链接。但我发现了一个关于这个问题的 rdar:openradar.me/18807663
-
谢谢@flinth。我已经有一段时间没有重新审视这一点来确认了,但这令人失望。
标签: ios swift cloudkit cksubscription ckreference