问题描述
我正在尝试为包含包含对用户的CKReference的字段的记录设置CKSubscription.但是,无论何时创建记录,它都会忽略compoundPredicate的这一部分,并且通知永远不会到来.在CKSubscription的谓词中使用CKReference有什么不同吗?我进入仪表板在我自己的用户recordID下输入新记录(在模拟器中运行另一个用户时),因为我相信我读到,如果记录来自设备,它将不会收到通知.非常感谢您提供任何见解,因为我已经坚持了一周,并且无法在网上找到与此相关的任何内容.我能够获得真正的类型谓词通知,所以我认为我的基本设置可以.
I'm trying to setup a CKSubscription for records that contain a field with a CKReference to the user. But anytime a record is created, it ignores this part of the compoundPredicate and the notification never comes. Is there something different about using a CKReference in a predicate for a CKSubscription? I go into the dashboard to enter a new record under my own user recordID (while running another user in simulator) because I believe I read that if the record comes from the device, it won't receive the notification. Any insight is greatly appreciated, as I've been stuck on this for a week and cannot find anything online specific to this. I'm able to get true type predicate notifications, so I think my basic setup is ok.
在仪表板中,我看到了两个测试用户的一个通用订阅,但没有一个用户的任何特定recordID(这有关系吗?):
In the dashboard I see one generic subscription for both test users, but not any specific recordID for either user (does this matter?):
Notifications.read (equals string)
Notifications.user (equals reference)
当我执行fetchAllSubscriptionsWithCompletionHandler方法时,它确实将当前用户对此设备的特定recordID显示为调试器中的CKReference.所以我不知道为什么它不起作用.
When I do the fetchAllSubscriptionsWithCompletionHandler method, it does show the current user's specific recordID for this device as the CKReference in the debugger. So I don't know why it won't work.
这是我的代码,首先在其中创建CKReference,然后将其用作谓词:
Here's my code where I create the CKReference first and then use it for my predicate:
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
推荐答案
我遇到了同样的问题,并在Apple网站上偶然发现了以下信息:
I had this same issue, and stumbled upon this piece of information on apples website:
当我将CKQuerySubscription的谓词更改为使用CKRecordID而不是CKReference时,它可以按预期工作.我意识到这是一个旧线程,但是我很难找到这个问题的答案,因为谓词在CKQuery和CKQuerySubscription之间的行为似乎有所不同.
When I changed my predicate for my CKQuerySubscription to use a CKRecordID instead of a CKReference it worked as expected. I realize this is an old thread but I struggled to find an answer to this issue, since the predicate seems to behave differently betwixt CKQuery and CKQuerySubscription.
这篇关于CKReference的CloudKit订阅通知未按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!