Copying a Versioning Object

You can call OBSCopyObjectRequest 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];
    
OBSCopyObjectRequest *request = [[OBSCopyObjectRequest alloc]initWithSrcBucketName:@"source-bucketname" srcObjectKey:@"objectname1" dstBucketName:@"destination-bucketname" dstObjectKey:@"objectname2"];
    
// Version ID of the to-be-copied versioning object
request.srcObjectVersionID = @"testVersionID";
[client copyObject:request completionHandler:^(OBSCopyObjectResponse *response, NSError *error){
    NSLog(@"%@",response);
}] ;