很抱歉,我找不到简单的英语答案,或者至少我看到的每个答案都假设我有一定数量的知识,而这些知识是不应该有的。我只需要删除一个CKSubscription
. 我该怎么做呢?所有提示和帮助将不胜感激。
问问题
186 次
1 回答
1
假设您没有要删除的订阅的订阅 ID,您应该首先获取所有订阅并找出要删除的订阅的订阅 ID:
[[[CKContainer defaultContainer] publicCloudDatabase] fetchAllSubscriptionsWithCompletionHandler:^(NSArray<CKSubscription *> * _Nullable subscriptions, NSError * _Nullable error) {
if (!error) {
//do your logic to find out which subscription you want to delete, and get it's subscriptionID
} else {
//handle error
}
}];
然后,现在您有了订阅 ID,只需将其删除:
CKModifySubscriptionsOperation *operation = [[CKModifySubscriptionsOperation alloc] initWithSubscriptionsToSave:nil subscriptionIDsToDelete:YOUR_SUBSCRIPTION_ID];
operation.modifySubscriptionsCompletionBlock = ^(NSArray <CKSubscription *> * __nullable savedSubscriptions, NSArray <NSString *> * __nullable deletedSubscriptionIDs, NSError * __nullable operationError) {
//handle the results when the operation has completed
};
[[[CKContainer defaultContainer] publicCloudDatabase] addOperation:operation];
不要忘记始终正确处理所有可能的错误。
于 2016-07-06T07:56:44.990 回答