General Examples of OBSClient
If no error is generated when you call an API in an instance of the OBSClient class, the operation is successful. Otherwise, the operation fails. Sample code is as follows:
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.
OBSClient *client = [[OBSClient alloc] initWithConfiguration:conf];
// Create a request for listing objects.
OBSListBucketsRequest *request = [OBSListBucketsRequest new];
// List objects.
OBSBFTask *task = [client listBuckets:request completionHandler:^(OBSListBucketsResponse *response, NSError *error) {
if(error){
// Rectify the fault.
}else{
// Obtain the result.
for(OBSBucket *bucket in response.bucketsList){
NSLog(@"bucketname=%@",bucket.name);
}
}
}];
[task waitUntilFinished];
- As an instance of OBSClient is declared as a local variable, when an OBSClient API is called, the waitUntilFinished operation must be performed on the request task to ensure that the instance of OBSClient is always valid during the request task execution. Otherwise, the network request may fail and the program may break down.
Last Article: Deleting an Object
Next Article: Initialization
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.