AWSContentManager Class Reference

Inherits from NSObject
Declared in AWSContentManager.h
AWSContentManager.m

Overview

The Content Manager manages caching and transfer of files from Amazon S3 and/or Amazon CloudFront. It lists files directly using S3, regardless of whether Amazon CloudFront is in use. It maintains a size-limited cache for files stored on the local device and provides operations to set the cache size limit and clear files from the local cache. It serves as the application’s interface into the Content Delivery feature. Content Manager instances are also used internally for the User Files feature. Requires the AWSS3 framework of AWSiOSSDK.

  maxCacheSize

Local cache size limit in bytes.

@property (nonatomic, assign) NSUInteger maxCacheSize

Declared In

AWSContentManager.h

  cachedUsedSize

Local cache bytes used.

@property (nonatomic, readonly) NSUInteger cachedUsedSize

Declared In

AWSContentManager.h

  pinnedSize

Number of bytes pinned in the cache. Pinned items do not count towards the cache size limit.

@property (nonatomic, readonly) NSUInteger pinnedSize

Declared In

AWSContentManager.h

+ defaultContentManager

Returns the default Content Manager singleton instance configured using the information provided in Info.plist file.

+ (instancetype)defaultContentManager

Discussion

Swift

let contentManager = AWSContentManager.defaultContentManager()

Objective-C

AWSContentManager *contentManager =  [AWSContentManager defaultContentManager];

Declared In

AWSContentManager.h

+ registerContentManagerWithConfiguration:forKey:

Creates a helper client for AWSContentManager for specified configuration with mentioned key. Use this method only if you require a helper client with specific configuration.

+ (void)registerContentManagerWithConfiguration:(AWSContentManagerConfiguration *)contentManagerConfiguration forKey:(NSString *)key

Parameters

contentManagerConfiguration

AWSContentManagerConfiguration object for the manager.

key

A string to identify the helper client.

Discussion

For example, set the configuration in - application:didFinishLaunchingWithOptions:

Swift

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
     let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
     let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
     AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration

     let contentManagerConfiguration = AWSContentManagerConfiguration(bucketName: "myBucket")

     AWSContentManager.registerContentManagerWithConfiguration(contentManagerConfiguration, forKey: "defaultManager")
 }

Objective-C

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                     identityPoolId:@"YourIdentityPoolId"];
     AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
                                                                          credentialsProvider:credentialsProvider];
     AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;                                                                          
     AWSContentManagerConfiguration *contentManagerConfiguration = [[AWSContentManager alloc] initWithBucketName:@"myBucketName"];
     [AWSContentManager registerUserFileManagerWithConfiguration:userFileManagerConfiguration
                                                          forKey:@"defaultManager"];     
     return YES;
 }

Then call the following to get the helper client:

Swift

let contentManager = AWSContentManager(forKey: "defaultManager")

Objective-C

AWSContentManager *contentManager = [AWSContentManager contentManagerForKey:@"defaultManager"];

Warning: After calling this method, do not modify the configuration object. It may cause unspecified behaviors.

Declared In

AWSContentManager.h

+ ContentManagerForKey:NS_SWIFT_NAME:

Retrieves the helper client associated with the key. You need to call + registerContentManagerWithConfiguration:forKey: before invoking this method. If + registerContentManagerWithConfiguration:forKey: has not been called in advance or the key does not exist, this method returns nil.

+ (instancetype)ContentManagerForKey:(NSString *)key NS_SWIFT_NAME

Parameters

key

A string to identify the helper client.

Return Value

An instance of AWSUserFileManager for specified key.

Discussion

Swift

 let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
 let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
 AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration

 let contentManagerConfiguration = AWSContentManagerConfiguration(bucketName: "myBucket")

 AWSContentManager.registerContentManagerWithConfiguration(contentManagerConfiguration, forKey: "defaultManager")

Objective-C

 AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                 identityPoolId:@"YourIdentityPoolId"];
 AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
                                                                      credentialsProvider:credentialsProvider];
 AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;                                                                          
 AWSContentManagerConfiguration *contentManagerConfiguration = [[AWSContentManager alloc] initWithBucketName:@"myBucketName"];
 [AWSContentManager registerUserFileManagerWithConfiguration:userFileManagerConfiguration
                                                      forKey:@"defaultManager"];     

Then call the following to get the helper client:

Swift

let ContentManager = AWSContentManager.ContentManager(forKey: "defaultManager")

Objective-C

AWSContentManager *ContentManager = [AWSContentManager ContentManagerForKey:@"defaultManager"];

Declared In

AWSContentManager.h

+ removeContentManagerForKey:

Removes the helper client associated with the key and release it.

+ (void)removeContentManagerForKey:(NSString *)key

Parameters

key

A string to identify the helper client.

Discussion

Swift

AWSContentManager.removeContentManagerForKey("defaultManager")

Objective-C

[AWSContentManager removeContentManagerForKey:@"defaultManager"];

Warning: Before calling this method, make sure no method is running on this client.

Declared In

AWSContentManager.h

– listAvailableContentsWithPrefix:marker:completionHandler:

Loads the list of available files in the Amazon S3 bucket under the folder specified by the prefix parameter. Results are paged with page size of 100 files. The marker parameter value returned from a call should be passed to a subsequent call, in order to page through the list of files.

- (void)listAvailableContentsWithPrefix:(nullable NSString *)prefix marker:(nullable NSString *)marker completionHandler:(void ( ^ ) ( NSArray<AWSContent*> *_Nullable contents , NSString *_Nullable marker , NSError *_Nullable error ))completionHandler

Parameters

prefix

Limits the response to keys that begin with the specified prefix.

marker

The key to start with when listing objects in a bucket. It loads object metadata from the S3 bucket in alphabetical order, starting with the key after the marker in order.

completionHandler

The completion handler that returns the results and error.

Discussion

Swift

let contentManager = AWSContentManager(forKey: "defaultManager")
contentManager.listAvailableContentsWithPrefix("prefix", marker: marker, completionHandler: {(contents: [AnyObject]?, nextMarker: String?, error: NSError?) -> Void in
        if let error = error {
            print("Failed to load the list of contents. \(error)")
            // handle content load failure here
        }
        if let contents = contents where contents.count > 0 {
            // Use marker and contents here
        }
        // handle successful result here
        })

Objective-C

AWSContentManager *contentManager = [AWSContentManager contentManagerForKey:@"defaultManager"];
[contentManager
    listAvailableContentsWithPrefix:@"prefix"
                             marker:marker
                  completionHandler:^(NSArray *contents, NSString *nextMarker, NSError *error) {
                    if (error) {
                        NSLog(@"Failed to load the list of contents. %@", error);
                        // handle content load failure here
                    }
                    if (contents.count > 0) {
                        // Use marker and contents here
                    }
                    // handle successful result here
                }];

Declared In

AWSContentManager.h

– listRecentContentsWithPrefix:completionHandler:

Returns a list of contents that fit in the available cache. The list is sorted by last modified date on the S3 bucket, the most recently modified one first.

- (void)listRecentContentsWithPrefix:(nullable NSString *)prefix completionHandler:(void ( ^ ) ( id _Nullable result , NSError *_Nullable error ))completionHandler

Parameters

prefix

Limits the response to keys that begin with the specified prefix.

completionHandler

The completion handler that returns the result and error.

Discussion

Swift

let contentManager = AWSContentManager(forKey: "defaultManager")
contentManager.listRecentContentsWithPrefix("prefix", completionHandler: {(result: AnyObject?, error: NSError?) -> Void in
        if let error = error {
            print("Failed to load the list of recent contents. \(error)")
            // Handle error here
        }
        if let downloadResult: [AWSContent] = result as? [AWSContent] {
            // Handle successful result here
            for content: AWSContent in downloadResult {
                // Handle each of the item in the result
            }
        }
    })

Objective-C

AWSContentManager *contentManager = [AWSContentManager contentManagerForKey:@"defaultManager"];
[contentManager listRecentContentsWithPrefix:@"prefix"
                           completionHandler:^(id result, NSError *error) {
                                       for (AWSContent *content in result) {
                                           // Handle each of the item in result
                                        }
                                    }];

Declared In

AWSContentManager.h

– clearCache

Removes all cached contents. It does not modify the remote objects.

- (void)clearCache

Declared In

AWSContentManager.h

– contentWithKey:

Returns an instance of AWSContent for a given key. You can use this method to download content without first load its metadata using - loadContentMetadataWithPrefix:marker:completionHandler:.

- (AWSContent *)contentWithKey:(NSString *)key

Parameters

key

The key of the content.

Return Value

An instance of AWSContent.

Declared In

AWSContentManager.h