CloudKit fetch all subscriptions from the current user

﹥>﹥吖頭↗ 提交于 2019-12-21 18:13:56

问题


I manage to save, change and delete records in Apples CloudKit. I even got notifications working with subscriptions, what I can not find out is, how do i list all subscriptions for the current user.

Here is my code so far:

let operation = CKFetchSubscriptionsOperation()
operation.fetchSubscriptionCompletionBlock = { (d, e) -> Void in
    println("got subscription")
    if e != nil {
        println("Error")
        dump(e)
    }
    dump(d)
}
publicDatabase.addOperation(operation)

What I got is:

got subscription
Error
- <CKError 0x14db0ed0: "Invalid Arguments" (12)> #0
- 0 key/value pairs

What are the Invalid Arguments? And how do i get a list of all saved subscriptions?


回答1:


If you want to do something with your subscriptions, then you could use something like this:

var database = CKContainer.defaultContainer().publicCloudDatabase
database.fetchAllSubscriptionsWithCompletionHandler({subscriptions, error in
        for subscriptionObject in subscriptions {
            var subscription: CKSubscription = subscriptionObject as CKSubscription
            ..
        }
    }



回答2:


I haven't tried this yet but according to the docs; fetchAllSubscriptionsOperation() will get all subscriptions for the user in the current database, assigning the value of this call to fetchSubscriptionCompletionBlock should then work. Adjust the following line of code to:

let operation = CKFetchSubscriptionsOperation.fetchAllSubscriptionsOperation()

Quick Help Notes

Again, according to the docs fetchAllSubscriptionsWithCompletionHandler will fetch all subscriptions on the current database:



来源:https://stackoverflow.com/questions/27203023/cloudkit-fetch-all-subscriptions-from-the-current-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!