初始化SDK
更新時間 2025-10-11 11:26:29
最近更新時間: 2025-10-11 11:26:29
分享文章
接入方式
方式一:使用官網下載的SDK
在官網下載SDK,下載地址:。
下載完成之后,解壓到項目根路徑下,配置Podfile
target 'CtyunS3Demo' do
pod 'AWSS3', :path => './oss-ios-sdk'
pod 'AWSCore', :path => './oss-ios-sdk'
end方式二:直接使用aws的SDK
直接配置Podfile
target 'CtyunS3Demo' do
pod 'AWSS3'
end初始化SDK
注意:直接在客戶端上使用主賬號存在賬號泄露的風險,在客戶端上必須使用sts功能生成的臨時賬號,此初始化流程只能用于測試。如何使用sts初始化參考 STS相關接口。
引用sdk的頭文件
#import <AWSS3/AWSS3.h>通過sdk使用s3服務的時候主要需要設置3個配置參數,accessKey,secretKey和endpoint,使用以下方法進行設置,完成sdk的初始化。
-(id)init {
if (self = [super init]) {
AWSStaticCredentialsProvider *credentialsProvider = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:@"填入你的accesskey" secretKey:@"填入你的secretkey"];
AWSEndpoint *endPoint = [[AWSEndpoint alloc] initWithURLString:@"//填入S3的地址和端口"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc]
initWithRegion:AWSRegionUSEast1
endpoint:endPoint
credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
self.s3 = [AWSS3 defaultS3];
}
return self;
}參數說明:
| 參數 | 說明 |
|---|---|
| accessKey | 用戶賬號 access key |
| secretKey | 用戶賬號 secret key |
| endpoint | 天翼云資源池的地址,必須指定http或https前綴 |