CKReference的CloudKit订阅通知未按预期工作 [英] CloudKit Subscription Notification for CKReference Not Working As Expected

查看:83
本文介绍了CKReference的CloudKit订阅通知未按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为包含包含对用户的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:

在创建其谓词包含CKReference字段的预订时,请确保在创建谓词时将CKRecordID对象用作该字段的值.在这种情况下,当前无法使用CKRecord对象.

When creating a subscription whose predicate contains a CKReference field, be sure to use a CKRecordID object as the value for the field when creating the predicate. Using a CKRecord object in this case doesn't currently work.

当我将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订阅通知未按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆