### Create OSSTask for Operations Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Initiate an operation, such as getting an object, which returns an OSSTask immediately. ```objc OSSTask * task = [client getObject:get]; ``` -------------------------------- ### List Generated Frameworks Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Navigate to the Products directory and list its contents to find the generated framework. ```bash cd Products && ls ``` -------------------------------- ### Build iOS Framework Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Execute the script to package the OSS iOS SDK into a framework. ```bash sh ./buildiOSFramework.sh ``` -------------------------------- ### Navigate to SDK Directory Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Change the current directory to the cloned OSS iOS SDK project. ```bash cd aliyun-oss-ios-sdk ``` -------------------------------- ### Add Pod Dependency Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Include the AliyunOSSiOS pod in your project's Podfile for dependency management. ```ruby pod 'AliyunOSSiOS' ``` -------------------------------- ### Initialize OSSClient with STS Authentication Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Initializes the OSSClient using STS authentication. This is the recommended mode for mobile applications. Ensure you have a valid STS URL and endpoint configured. ```objc @interface AppDelegate () @property (nonatomic, strong) OSSClient *client; @end /** * the url to fetch sts info,for detail please refer to https://help.aliyun.com/document_detail/31920.html */ #define OSS_STS_URL @"oss_sts_url" /** * the endpoint for OSS used in app, for detail please refer to https://help.aliyun.com/document_detail/31837.html */ #define OSS_ENDPOINT @"your bucket's endpoint" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // initialize OSSClient [self setupOSSClient]; return YES; } - (void)setupOSSClient { // initialize credential provider,which auto fetch and update sts info from sts url. OSSAuthCredentialProvider *credentialProvider = [[OSSAuthCredentialProvider alloc] initWithAuthServerUrl:OSS_STS_URL]; // set config for oss client networking OSSClientConfiguration *cfg = [[OSSClientConfiguration alloc] init]; _client = [[OSSClient alloc] initWithEndpoint:OSS_ENDPOINT credentialProvider:credentialProvider clientConfiguration:cfg]; } ``` -------------------------------- ### Clone OSS iOS SDK Repository Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Clone the official Alibaba Cloud OSS SDK for iOS repository from GitHub. ```bash git clone git@github.com:aliyun/aliyun-oss-ios-sdk.git ``` -------------------------------- ### Required System Libraries for IPv6 Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Include these system libraries for compatibility with IPv6-only networks, in addition to the '-ObjC' linker flag. ```text libresolv.tbd SystemConfiguration.framework CoreTelephony.framework ``` -------------------------------- ### Linker Flags Configuration Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Add '-ObjC' to 'Other Linker Flags' in your project's build settings. If '-force_load' is used, specify the framework path. ```text -ObjC -force_load /AliyunOSSiOS ``` -------------------------------- ### Configure Asynchronous Callback with OSSTask Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Attach a continuation block to an OSSTask to handle the result or completion of the asynchronous operation. ```objc [task continueWithBlock: ^(OSSTask *task) { // do something ... return nil; }]; ``` -------------------------------- ### Upload a File to OSS Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Uploads a file to an OSS bucket. You can upload NSData directly. Configure a continuation block for asynchronous callbacks or use waitUntilFinished for blocking calls. ```objc OSSPutObjectRequest * put = [OSSPutObjectRequest new]; put.bucketName = @""; put.objectKey = @""; put.uploadingData = ; // Directly upload NSData put.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) { NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend); }; OSSTask * putTask = [client putObject:put]; [putTask continueWithBlock:^id(OSSTask *task) { if (!task.error) { NSLog(@"upload object success!"); } else { NSLog(@"upload object failed, error: %@" , task.error); } return nil; }]; // Wait until the task is finished // [putTask waitUntilFinished]; ``` -------------------------------- ### Import OSS SDK Header Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Import the main header file for the OSS iOS SDK in your Objective-C project. ```objc #import ``` -------------------------------- ### Download a Specified Object from OSS Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Downloads a specified object from an OSS bucket as NSData. You can monitor download progress and handle completion or errors asynchronously. A blocking call option is also available. ```objc OSSGetObjectRequest * request = [OSSGetObjectRequest new]; request.bucketName = @""; request.objectKey = @""; request.downloadProgress = ^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) { NSLog(@"%lld, %lld, %lld", bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); }; OSSTask * getTask = [client getObject:request]; [getTask continueWithBlock:^id(OSSTask *task) { if (!task.error) { NSLog(@"download object success!"); OSSGetObjectResult * getResult = task.result; NSLog(@"download result: %@", getResult.downloadedData); } else { NSLog(@"download object failed, error: %@" ,task.error); } return nil; }]; // Use a blocking call to wait until the task is finished // [task waitUntilFinished]; ``` -------------------------------- ### Configure HTTPS Endpoint Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Ensure all network requests comply with ATS by using an endpoint with the 'https://' prefix. This is supported from V2.6.0 onwards. ```text https:// ``` -------------------------------- ### Synchronous Wait for OSSTask Source: https://github.com/aliyun/aliyun-oss-ios-sdk/blob/master/README.md Wait for an OSSTask to complete before proceeding with the execution flow. ```objc [task waitUntilFinished]; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.