如何删除 Objective-c 中的 cksubscription?
How do i delete cksubscription in Objective-c?
抱歉,我找不到通俗易懂的英语答案,或者至少我看到的每个答案都假设我有一定的知识,而这些知识是不应该有的。我只需要删除一个CKSubscription
。我该怎么做呢?非常感谢所有提示和帮助。
假设您没有要删除的订阅的subscriptionID,您应该首先获取所有订阅并找出要删除的订阅的subscriptionID:
[[[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
}
}];
那么,既然您已经有了 subscriptionID,只需将其删除即可:
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];
不要忘记始终妥善处理所有可能的错误。
抱歉,我找不到通俗易懂的英语答案,或者至少我看到的每个答案都假设我有一定的知识,而这些知识是不应该有的。我只需要删除一个CKSubscription
。我该怎么做呢?非常感谢所有提示和帮助。
假设您没有要删除的订阅的subscriptionID,您应该首先获取所有订阅并找出要删除的订阅的subscriptionID:
[[[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
}
}];
那么,既然您已经有了 subscriptionID,只需将其删除即可:
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];
不要忘记始终妥善处理所有可能的错误。