Developer Console

SDK for iOS Best Practices

Best practices for using the SDK for iOS

ACDSKClient

Shared Instance

It is easy, though not required, to create a shared instance of ACDSKClient that you can use throughout your app. One way is to create a new category on ACDSKClient. Just be sure to provide a way to reset the client, so that you are able to do so on logout.

ACDSKClient+Convenience.h

  //
  //  ACDSKClient+Convenience.h
  //

  #import <ACDSKit/ACDSKit.h>

  @interface ACDSKClient (Convenience)

  /**
   Shared instance of ACDSKClient. Uses AMZNAuthorizationProvider as its auth token provider.
   */
  + (instancetype)sharedInstance;

  /**
   Resets the shared instance of ACDSKClient. Should be called on logout.
   */
  + (void)resetSharedInstance;

  @end

ACDSKClient+Convenience.m

  //
  //  ACDSKClient+Convenience.m
  //

  #import "ACDSKClient+Convenience.h"
  #import "AMZNAuthorizationProvider.h"

  @implementation ACDSKClient (Convenience)

  + (instancetype)sharedInstance {
      @synchronized(self) {
          if (_sharedInstance == nil) {
              _sharedInstance = [self clientWithTokenProvider:^NSString *{
                  NSError *error = nil;
                  return [[AMZNAuthorizationProvider sharedProvider] fetchAuthTokenSynchronously:&error];
              }];
          }
          return _sharedInstance;
      }
  }

  + (void)resetSharedInstance {
      @synchronized(self) {
          _sharedInstance = nil;
      }
  }

  @end

Whenever you want to interact with Amazon Drive, you can simply use the [ACDSKClient sharedInstance] method.

  [[ACDSKClient sharedInstance] uploadFile:...]

Responding to Logout

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.

Login with Amazon

Login Helper Code

It is entirely possible to work directly with Login with Amazon, and you can learn how to do so with the Login with Amazon Getting Started guide. If you'd rather focus on developing the rest of your app functionality however, an extra package of open source code is available to be added to your project which makes working with Login with Amazon much easier.

  1. In your Xcode project, click on the File drop-down menu and select the Add Files... option.
  2. Under the Destination options, click on the Copy items if needed option to select it.
  3. Navigate to the location that you unzipped the SDK for iOS and select the directory named LoginHelper. It should be located at SDK-iOS/iOS/AmazonCloudDrive/1.0.0/samples/ACDSKitSampleApp/ACDSKitSampleApp/LoginHelper.
  4. Open AMZNLoginWithAmazonConstants.h and set the value of the macro kAMZNCloudDriveAccessTokenActiveScope to an array of the scopes for which your app is requesting access from the user. The default value is kAMZNCloudDriveAccessTokenAllScope, but you should only request the scopes that are required for your app to function. Note: The permission level you request when you add your security profile to the allow list with Amazon Drive affects your access.
    • To request all scopes:

          #define kAMZNCloudDriveAccessTokenActiveScope kAMZNCloudDriveAccessTokenAllScope
      
    • To request read-only scopes:

          #define kAMZNCloudDriveAccessTokenActiveScope @[kAMZNCloudDriveAccessTokenReadScope]
      

This provides a [AMZNAccountManager sharedProvider] object that you can use for easy asynchronous calls to trigger login and logout. It also provides a [AMZNAuthorizationProvider sharedProvider] object that you can use as the required auth token provider for ACDSKClient.

Support

If you have any questions, see the Developer Forum.