Deleting a Bucket

You can call deleteBucket to delete a bucket. 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 a bucket.
OBSDeleteBucketRequest *deleteRequest = [[OBSDeleteBucketRequest alloc] initWithBucketName:@"bucketname"];
[client deleteBucket:deleteRequest completionHandler:^(OBSDeleteBucketResponse *response, NSError *error) {
    NSLog(@"%@",response);
}];
  • Only empty buckets (without objects and part fragments) can be deleted.
  • Bucket deletion is a non-idempotence operation and an error will be reported if the to-be-deleted bucket does not exist.