AWSContent Class Reference

Inherits from NSObject
Declared in AWSContentManager.h
AWSContentManager.m

Overview

The content object that holds the cached data and its metadata.

A category to add remote file removal to AWSContent.

Other Methods

  key

The Amazon S3 key associated with the content.

@property (nonatomic, readonly) NSString *key

Declared In

AWSContentManager.h

  directory

Shows if the content is a directory.

@property (nonatomic, readonly, getter=isDirectory) BOOL directory

Declared In

AWSContentManager.h

  status

The status of the content.

@property (nonatomic, readonly) AWSContentStatusType status

Declared In

AWSContentManager.h

  progress

The transfer progress.

@property (nonatomic, readonly) NSProgress *progress

Declared In

AWSContentManager.h

  knownRemoteByteCount

The last known size reported by the Amazon S3. May be different from the actual size if the file was modified on the server.

@property (nonatomic, readonly) NSUInteger knownRemoteByteCount

Declared In

AWSContentManager.h

  knownRemoteLastModifiedDate

The last known last modified date reported by the Amazon S3. May be different from the actual last modified date if the file was modified on the server.

@property (nonatomic, readonly) NSDate *knownRemoteLastModifiedDate

Declared In

AWSContentManager.h

  cachedData

The cached data object.

@property (nonatomic, readonly) NSData *cachedData

Declared In

AWSContentManager.h

  fileSize

The cached data size.

@property (nonatomic, readonly) NSUInteger fileSize

Declared In

AWSContentManager.h

  downloadedDate

The date the cached data was downloaded.

@property (nonatomic, readonly) NSDate *downloadedDate

Declared In

AWSContentManager.h

  cached

Wheather the content is locally cached.

@property (nonatomic, readonly, getter=isCached) BOOL cached

Declared In

AWSContentManager.h

  pinned

Weather the content is pinned. Pinned objects are not subject to the content cache limit.

@property (nonatomic, readonly, getter=isPinned) BOOL pinned

Declared In

AWSContentManager.h

– downloadWithDownloadType:pinOnCompletion:progressBlock:completionHandler:

Downloads a file from the remote server.

- (void)downloadWithDownloadType:(AWSContentDownloadType)loadingType pinOnCompletion:(BOOL)pinOnCompletion progressBlock:(void ( ^ _Nullable ) ( AWSContent *content , NSProgress *progress ))progressBlock completionHandler:(void ( ^ ) ( AWSContent *_Nullable content , NSData *_Nullable data , NSError *_Nullable error ))completionHandler

Parameters

loadingType

Specifies the loading behavior for downloading data.

pinOnCompletion

When set to YES, it pins the content on completion. You can download a content that does not fit in the content cache by setting it to YES.

progressBlock

The progress feedback block.

completionHandler

The completion handler block.

Discussion

Swift

func downloadContent(content: AWSContent, pinOnCompletion: Bool) {
    content.downloadWithDownloadType( .IfNewerExists, pinOnCompletion: pinOnCompletion, progressBlock: {(content: AWSContent?, progress: NSProgress?) -> Void in
            // Handle progress feedback
        }, completionHandler: {(content: AWSContent?, data: NSData?, error: NSError?) -> Void in
            if let error = error {
                print("Failed to download a content from a server.)")
                // Handle error here                    
                return
            }
            // Handle successful download here
        })
}

Objective-C

- (void)downloadContent:(AWSContent *)content
        pinOnCompletion:(BOOL)pinOnCompletion {
    [content downloadWithDownloadType:AWSContentDownloadTypeIfNewerExists
                      pinOnCompletion:pinOnCompletion
                        progressBlock:^(AWSContent *content, NSProgress *progress) {
                        // Handle progress feedback
                    }
                completionHandler:^(AWSContent *content, NSData *data, NSError *error) {
                    if (error) {
                        NSLog(@"Failed to download a content from a server. %@", error);
                        // Handle error here
                        return;
                    }
                    // Handle successful download here
                }];
    }

Declared In

AWSContentManager.h

– getRemoteFileURLWithCompletionHandler:

Gets Presigned URL or the Cloud Front URL for the file.

- (void)getRemoteFileURLWithCompletionHandler:(void ( ^ ) ( NSURL *_Nullable url , NSError *_Nullable error ))completionHandler

Parameters

completionHandler

The completion handler block.

Discussion

Swift

func getContentURL(content: AWSContent) {
    content.getRemoteFileURLWithCompletionHandler({ (url: NSURL?, error: NSError?) -> Void in
        guard let url = url else {
            NSLog("Error getting URL for file. \(error)")
            return
        }
        // Handle successfully generated URL here
    })
}

Objective-C

- (void)getContentURL:(AWSContent *)content {
    [content getRemoteFileURLWithCompletionHandler:^(NSURL *url, NSError *error) {
        if (error) {
            NSLog(@"Failed to get a valid URL from a server. %@", error);
        }
        // handle successfully generated URL here
    }];
}

Declared In

AWSContentManager.h

– pin

Pins the locally cached object. Pinned objects are not subject to the content cache limit.

- (void)pin

Declared In

AWSContentManager.h

– unPin

Unpins the pinned object. It may purge the content cache if the content cache does not have enough available space to fit the unpinned data.

- (void)unPin

Declared In

AWSContentManager.h

– removeLocal

Removes locally cached data regardless of the pinning status.

- (void)removeLocal

Declared In

AWSContentManager.h

Other Methods

– removeRemoteContentWithCompletionHandler:

Removes the remote file associated with AWSContent.

- (void)removeRemoteContentWithCompletionHandler:(void ( ^ ) ( AWSContent *content , NSError *error ))completionHandler

Parameters

completionHandler

The completion handler block.

Discussion

Swift

func removeContent(content: AWSContent) {
    content.removeRemoteContentWithCompletionHandler({(content: AWSContent?, error: NSError?) -> Void in
        if let error = error {
            print("Failed to delete an object from the remote server. \(error)")
        } else {
            print("Success")
            // Do something further
        }
    })
}

Objective-C

- (void)removeContent:(AWSContent *)content {
    [content removeRemoteContentWithCompletionHandler:^(AWSContent *content, NSError *error) {
        if (error) {
            NSLog(@"Failed to delete an object from the remote server. %@", error);
        } else {
            NSLog(@"Success");
            // Do something further
        }
    }];
}

Declared In

AWSUserFileManager.h