tencent cloud

Quick Start
Last updated: 2026-01-07 10:49:05
Quick Start
Last updated: 2026-01-07 10:49:05

Preparations

You need an iOS app, which can be your existing project or a new empty project.
Ensure your iOS app target is iOS 9 or higher.

Step 1: Installing the SDK

Add the following dependency to your project's Podfile and execute pod install.
pod "QCloudCOSSMH/Api"

Step 2: Getting Started

Import the Header File

#import <QCloudCOSSMHApi.h>

Setting Access Domain

Before using the related services provided by the SDK, you must set the access domain for the SDK.
// Publish the configuration domain name
[QCloudSMHBaseRequest setBaseRequestHost:@"<libraryId>.api.tencentsmh.cn" targetType:QCloudECDTargetRelease];
[QCloudSMHBaseRequest setTargetType:QCloudECDTargetRelease];
Note:
After a media library is created in the console, the console will display the dedicated domain name generated for you. This domain name is a prerequisite for accessing all services. It is strongly recommended that you set your dedicated domain name via the SDK after initializing your application.


Initializing SMH Service and Implementing the accessToken Protocol

Note:
The User module does not require accessToken. If you only use User, you can skip this step.
How to obtain accessToken when integrating API and User.
The module API needs to carry accessToken when making a request, so it is necessary to implement the QCloudSMHAccessTokenProvider protocol to obtain the QCloudSMHSpaceInfo object containing accessToken and spaceId, etc. from this protocol and pass it to the SDK with parameter continueBlock.
- (void)accessTokenWithRequest:(QCloudSMHBizRequest *)request
urlRequest:(NSURLRequest *)urlRequst
compelete:(QCloudSMHAuthentationContinueBlock)continueBlock {
// First get the response containing access token information from your access token server
QCloudSMHSpaceInfo * spaceInfo = [QCloudSMHSpaceInfo new];
spaceInfo.accessToken = @""; // Access token
spaceInfo.expiresIn = @""; // Access token valid duration in seconds
spaceInfo.libraryId = @""; //
spaceInfo.spaceId = @"";
continueBlock(sapceInfo, nil);
}
The SDK provides a QCloudSMHAccessTokenFenceQueue scaffold to cache and reuse accessToken. The scaffold will call the protocol method again to reobtain a new key until the key expiration time is above the device's current time.
Note:
It is recommended to place the initialization process in AppDelegate or a program singleton.
To use scaffolding, you need to implement the QCloudAccessTokenFenceQueueDelegate protocol.
1. Initialize the scaffold.
@property (nonatomic) QCloudSMHAccessTokenFenceQueue *fenceQueue;

self.fenceQueue = [QCloudSMHAccessTokenFenceQueue new];
self.fenceQueue.delegate = self;
2. Implement QCloudAccessTokenFenceQueueDelegate.
- (void)fenceQueue:(QCloudSMHAccessTokenFenceQueue *)queue
request:(QCloudSMHBizRequest *)request
requestCreatorWithContinue:(QCloudAccessTokenFenceQueueContinue)continueBlock {
// First get the response containing access token information from your access token server
QCloudSMHSpaceInfo * spaceInfo = [QCloudSMHSpaceInfo new];
spaceInfo.accessToken = @""; // Access token
spaceInfo.expiresIn = @""; // Access token valid duration in seconds
spaceInfo.libraryId = @""; //
spaceInfo.spaceId = @"";
continueBlock(sapceInfo, nil);
}

// In this method, use scaffold to handle request with sdk internal cache accessToken and use continueBlock callback to sdk. If
// If the accessToken cached in the sdk expires or is not available, redirect to the above method to request the latest accessToken and cache it in the sdk.
- (void)accessTokenWithRequest:(QCloudSMHBizRequest *)request
urlRequest:(NSURLRequest *)urlRequst
compelete:(QCloudSMHAuthentationContinueBlock)continueBlock {
[self.fenceQueue performRequest:request
withAction:^(QCloudSMHSpaceInfo *_Nonnull accessToken, NSError *_Nonnull error) {
if (error) {
continueBlock(nil, error);
} else {
continueBlock(accessToken, nil);
}
}];
}
Note:
If only the API module is required, a business server-side interface that can obtain access tokens for the SMH service is needed. For details about access tokens, see Generating Access Tokens.
Implement the QCloudSMHAccessTokenProvider protocol, obtain the accessToken from this protocol, wrap it into a QCloudSMHSpaceInfo object, and pass it to the SDK via the continueBlock parameter.

Step 3: Access the SMH Service

Take file list as an example. The access method for other APIs is similar.
QCloudSMHListContentsRequest *req = [QCloudSMHListContentsRequest new];
// The user's Space ID
req.spaceId = @"spaceId";
// The user's library ID
req.libraryId = @"libraryId";

// Directory path or album name. For multi-level directories, use slashes (/) to separate, such as foo/bar. For the root directory, leave this parameter blank.
req.dirPath = @"dirpath";
[req setFinishBlock:^(QCloudSMHContentListInfo *_Nullable result, NSError *_Nullable error) {
// result file list data
// error message
}];
// Initiate a request
[[QCloudSMHService defaultSMHService] listContents:req];

General Parameter Introduction

libraryId: Media Library ID, required parameter.
spaceId: Space ID. If the media library is in single-tenant mode, this parameter is fixed as hyphen (-). If the media library is in multi-tenant mode, you must specify this parameter.
accessToken: Access token, required parameter.
Note:
For more concepts, see Basic Concepts.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback