Developer Console

Amazon Drive SDK for iOS

The SDK Client

Creating and Managing a Client

A client requires a block that returns an auth token. The easiest way to provide an auth token is with the open source AMZNAuthorizationProvider, although you may implement your own provider if you prefer.

  ACDSKClient *client = [ACDSKClient clientWithTokenProvider:^NSString *{
      NSError *error = nil;
      return [[AMZNAuthorizationProvider sharedProvider] fetchAuthTokenSynchronously:&error];
  }];

It is easy, though not required, to create a shared instance of ACDSKClient that you can use throughout your app. For more details on how to set up a shared instance of ACDSKClient, see the ACDSKClient section of the iOS Best Practices documentation. No matter how you create the client, be sure to keep a strong reference to it in order to prevent it from being deallocated before a request is sent.

When logout occurs, you should deallocate any existing instance of ACDSKClient. You should also cancel any client tasks in progress, or at least ignore the response for any existing requests.

Making a Request

Constructing a Request

To make an API call using the client, you must create an instance of the request object for that API. Example: To call uploadFile, you must create an instance of ACDSKUploadFileRequest. Check the documentation for required parameters for the request as well as additional optional ones.

  // Create the request object and set the required parameters
  ACDSKUploadFileRequest *uploadFileRequest = [ACDSKUploadFileRequest new];
  // Set the local path of the file to upload
  uploadFileRequest.filePath = localFilePath;
  // Set the name to use for the file in Amazon Drive
  uploadFileRequest.name = @"NewCloudDriveFile";

  // Make asynchronous request using instance of ACDSKClient
  [client uploadFile:uploadFile:request fail:^(NSError *error) {
      // Handle failure
  } progress:^(float progressed) {
      // Handle progress
  } success:^(ACDSKUploadFileResponse *response) {
      // Handle success
  }];

Making Calls and Handling Errors

ACDSKClient requests are made asynchronously and do not block the calling thread. They are block-based and take a failure block that provides an error with the reason for the failure, as well as a success block that provides a response object. Almost every request class has a parallel response class, such as the ACDSKAccountInfoRequest class and ACDSKAccountInfoResponse class or the ACDSKListNodesRequest and ACDSKListNodesResponse class. Some API calls result in an empty response, represented by the ACDSKEmptyResponse class.

Canceling a Request

Every ACDSKClient method for making a request to Amazon Drive returns a ACDSKTask object which can be used to keep a reference to the request. This task object enables a developer to cancel a request simply by calling cancel on the corresponding task. This will result in the request fail block being run with error code AMZNCDSKURLErrorOperationCancelled.

  // Set up client
  ACDSKClient *client = // ...
  // Set up request
  ACDSKDownloadFileRequest *downloadFileRequest = // ...

  // Keep a reference to the task returned by the client method
  ACDSKTask *downloadFileTask = [client downloadFile:downloadFileRequest fail:^(NSError *error) {
    if ([error.domain isEqualToString:AMZNCDSKURLErrorDomain] && error.code == AMZNCDSKURLErrorOperationCancelled) {
      // Request was cancelled
    }
  } progress:^(float progressed) {
      // ...
  } success:^(ACDSKDownloadFileResponse *response) {
      // ...
  }];

  // Cancel the request
  [downloadFileTask cancel];

Support

If you have any questions, see the Developer Forum.