1

この方法を使用して、画像/ビデオを S3 にアップロードしています(以下のコードを参照)。

ユーザーがアプリをバックグラウンドにし、後でアプリを開いた場合、一時停止/再開を使用してすべてのアップロードを再開できますか? SDKでアップロードを永続的にキャッシュしているようself.cache.diskCacheです. つまり、UIBackgroundTask を使用して、期限切れハンドラーでダウンロードを一時停止し、アプリがフォアグラウンドに戻ったときに resumeAll を使用できますか?

NSURLSession を使用して永続的なアップロードを行う方法に関するこの講演を見ていて、現在のアプリでそれを行うための良い方法を設計しようとしています。

このようなもの:

- (void)applicationWillEnterForeground:(NSNotification *)notification
{
    [self.transferManager resumeAll:^(AWSRequest *request) {
        POLYLog(@"request %@",request.description);
    }];
}

- (void)applicationDidEnterBackground:(NSNotification *)notification
{
    UIApplication* app = [UIApplication sharedApplication];
    __block UIBackgroundTaskIdentifier task;

    task = [app beginBackgroundTaskWithExpirationHandler:^{
        [self.transferManager pauseAll];
        [app endBackgroundTask:task];
        task = UIBackgroundTaskInvalid;
    }];
}

AWS ドキュメントからの参照:

// Construct the NSURL for the download location.
NSString *downloadingFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"downloaded-myImage.jpg"];
NSURL *downloadingFileURL = [NSURL fileURLWithPath:downloadingFilePath];

// Construct the download request.
AWSS3TransferManagerDownloadRequest *downloadRequest = [AWSS3TransferManagerDownloadRequest new];

downloadRequest.bucket = @"myBucket";
downloadRequest.key = @"myImage.jpg";
downloadRequest.downloadingFileURL = downloadingFileURL;
Now we can pass the download request to the download: method of the TransferManager client. The AWS Mobile SDK for iOS uses AWSTask to support asynchronous calls to Amazon Web Services. The download: method is asynchronous and returns a AWSTask object, so we’ll use it accordingly:

[[transferManager upload:uploadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor]
                                                   withBlock:^id(AWSTask *task) {
                                                       if (task.error) {
                                                           if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
                                                               switch (task.error.code) {
                                                                   case AWSS3TransferManagerErrorCancelled:
                                                                   case AWSS3TransferManagerErrorPaused:
                                                                       break;

                                                                   default:
                                                                       NSLog(@"Error: %@", task.error);
                                                                       break;
                                                               }
                                                           } else {
                                                               // Unknown error.
                                                               NSLog(@"Error: %@", task.error);
                                                           }
                                                       }

                                                       if (task.result) {
                                                           AWSS3TransferManagerUploadOutput *uploadOutput = task.result;
                                                           // The file uploaded successfully.
                                                       }
                                                       return nil;
                                                   }];
4

0 に答える 0