问题
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