edit-icon download-icon

iOS version

Last Updated: Jan 02, 2018
  • Environment requirements

    iOS 7.0 or a later version

  • Installation

    OSS iOS SDK

    Download the upload SDK

    • Directly introduce the frameworks

      Introduce the frameworks of the OSS iOS SDK and VODUpload iOS SDK.

      In Xcode, drag the frameworks and drop them to your target, and select “Copy items if needed” in the displayed dialog box.

    • Introduce the header file to your project

      1. #import <VODUpload/VODUploadClient.h>

      NOTE: After you introduce the frameworks, add -ObjC to Other Linker Flags of Build Settings in your project. If the -force_load option has been configured for your project, add -force_load <framework path>/AliyunOSSiOS.

    • Compatible with IPv6-Only networks

      The OSS mobile SDK has introduced the HTTPDNS for domain name resolution to avoid domain name resolution hijacking in a wireless network and directly uses IP addresses for requests to the server. In an IPv6-Only network, compatibility issues may occur. The app officially issued the review requirements for apps, requiring apps to be IPv6-only network compatible. To this end, the SDK starts to be compatible from V2.5.0. In the new version, apart from -ObjC settings, two system libraries must be introduced:

      1. libresolv.tbd
      2. SystemConfiguration.framework
  • Create a VODUpload instance

    Set the callback function.

    1. OnUploadStartedListener testUploadStartedCallbackFunc = ^(UploadFileInfo* fileInfo) {
    2. NSLog(@"upload started .");
    3. };
    4. OnUploadSucceedListener testSuccessCallbackFunc = ^(NSString* filePath){
    5. NSLog(@"file:%@ upload success!", filePath);
    6. };
    7. OnUploadFailedListener testFailedCallbackFunc = ^(NSString* filePath, NSString* code, NSString* message){
    8. NSLog(@"failed code = %@, error message = %@", code, message);
    9. };
    10. // Unite: byte
    11. OnUploadProgressListener testProgressCallbackFunc = ^(NSString* filePath, long uploadedSize, long totalSize) {
    12. NSLog(@"progress uploadedSize : %li, totalSize : %li", uploadedSize, totalSize);
    13. };
    14. OnUploadTokenExpiredListener testTokenExpiredCallbackFunc = ^{
    15. NSLog(@"*token expired.");
    16. // get token and call resmeUploadWithAuth.
    17. };
    18. OnUploadRertyListener testUploadRertyListener = ^{
    19. NSLog(@"retry begin.");
    20. };
    21. OnUploadRertyResumeListener testUploadRertyResumeListener = ^{
    22. NSLog(@"retry resume.");
    23. };
    24. VODUploadListener *listener;
    25. listener = [[VODUploadListener alloc] init];
    26. listener.started = testUploadStartedCallbackFunc;
    27. listener.success = testSuccessCallbackFunc;
    28. listener.failure = testFailedCallbackFunc;
    29. listener.progress = testProgressCallbackFunc;
    30. listener.expire = testTokenExpiredCallbackFunc;
    31. listener.retry = testUploadRertyListener;
    32. listener.retryResume = testUploadRertyResumeListener;
  • Initialize the upload SDK

    Enter the authorization information in either of the following ways:

    • AccessKey

      It is simple but not safe. It is recommended that this way be used in the test environment.

      1. VODUploadClient *uploader;
      2. [uploader init:<accessKeyId>
      3. accessKeySecret:<accessKeySecret>
      4. listener:listener];
    • Token

      It is safe but complex. It is recommended that this way be used in the production environment. A token is temporary and valid for a period. Therefore, sending a token is safe.

      1. VODUploadClient *uploader;
      2. [uploader init:<accessKeyId>
      3. accessKeySecret:<accessKeySecret>
      4. secretToken:<secretToken>
      5. expireTime:<expireTime>
      6. listener:listener];
  • List management

    • Add a file to be uploaded

      NOTE: The file size cannot exceed 4 GB.

      1. [uploader addFile:<uploadFilePath>
      2. endpoint:<endpoint> //For example: 'http://oss-cn-hangzhou.aliyuncs.com'
      3. bucket:<bucketName> // Enter the actual bucket name
      4. object:<objectKey>];

      During uploading, obtain the attributes (the title, tag, description, category, cover URL, and custom data) of a media set in the following way: addFile contains a reload function, in which the last parameter is a VodInfo object. The definitions are as follows:

      1. @interface VodInfo : NSObject
      2. @property (nonatomic, strong) NSString* title;
      3. @property (nonatomic, strong) NSString* tags;
      4. @property (nonatomic, strong) NSString* desc;
      5. @property (nonatomic, strong) NSNumber* cateId;
      6. @property (nonatomic, strong) NSString* userData;
      7. @property (nonatomic, strong) NSString* coverUrl;
    • Delete the uploaded file

      1. [uploader deleteFile:<index>];
    • Cancel upload of a single file in the list

      1. [uploader cancelFile:<index>];
    • Resume upload of a single file in the list

      1. [uploader resumeFile:<index>];
    • Obtain the upload file list

      1. [uploader listFiles];
    • Clear the upload file list

      1. [uploader clearFiles];
  • Upload control

    • Start upload

      1. [uploader start];
    • Stop upload

      1. [uploader stop];
    • Pause upload

      1. [uploader pause];
    • Resume upload

      1. [uploader resume];
    • Resume upload after the token is invalid

      1. [uploader resumeWithToken:<accessKeyId>
      2. accessKeySecret:<accessKeySecret>
      3. secretToken:<secretToken>
      4. expireTime:<expireTime>]
Thank you! We've received your feedback.