Deleting Versioning Objects

Deleting a Single Versioning Object

You can call OBSDeleteObjectRequest to pass the version ID (versionID) to copy a versioning object. Sample code is as follows:

static OBSClient *client;
NSString *endPoint = @"your-endpoint";
NSString *SK = @"*** Provide your Secret Key ***";
NSString *AK = @"*** Provide your Access Key ***";
    
// Initialize identity authentication.
OBSStaticCredentialProvider *credentialProvider = [[OBSStaticCredentialProvider alloc] initWithAccessKey:AK secretKey:SK];
    
//Initialize service configuration.
OBSServiceConfiguration *conf = [[OBSServiceConfiguration alloc] initWithURLString:endPoint credentialProvider:credentialProvider];
    
// Initialize an instance of OBSClient.
client = [[OBSClient alloc] initWithConfiguration:conf];
    
// Delete an object.
OBSDeleteObjectRequest *request = [[OBSDeleteObjectRequest alloc] initWithBucketName:@"bucketname" objectKey:@"objectname"];
    
// Set the version ID for a versioning object.
request.versionID = @"versionID";
    
[client deleteObject:request completionHandler:^(OBSDeleteObjectResponse *response, NSError *error) {
    NSLog(@"%@",response);
}];

Batch Deleting Versioning Objects

You can call OBSDeleteObjectsRequest to pass the version ID (versionID) of each to-be-deleted object to batch delete them. Sample code is as follows:

static OBSClient *client;
NSString *endPoint = @"your-endpoint";
NSString *SK = @"*** Provide your Secret Key ***";
NSString *AK = @"*** Provide your Access Key ***";
    
// Initialize identity authentication.
OBSStaticCredentialProvider *credentialProvider = [[OBSStaticCredentialProvider alloc] initWithAccessKey:AK secretKey:SK];
    
//Initialize service configuration.
OBSServiceConfiguration *conf = [[OBSServiceConfiguration alloc] initWithURLString:endPoint credentialProvider:credentialProvider];
    
// Initialize an instance of OBSClient.
client = [[OBSClient alloc] initWithConfiguration:conf];
    
// Delete objects in a batch.
OBSDeleteObjectsRequest *deleteRequest = [[OBSDeleteObjectsRequest alloc] initWithBucketName:@"bucketname"];
    
// List versioning objects.
OBSObjectToDelete *object = [[OBSObjectToDelete alloc] initWithObjectKey:@"objectname" versionID:@"versionID"];
OBSObjectToDelete *object1 = [[OBSObjectToDelete alloc] initWithObjectKey:@"objectname" versionID:@"versionID"];
    
deleteRequest.objectList = @[object,object1];
    
[client deleteObjects:deleteRequest completionHandler:^(OBSDeleteObjectsResponse *response, NSError *error) {
    NSLog(@"%@",response);
}];