Шаг 1
Настроить iOS проект.Шаг 2
Сделать свою имплементацию протокола AWSCredentialsProvider.// // MyCredentialsProvider.h // #import <Foundation/Foundation.h> #import "S3.h" #import "AWSCore.h" @interface MyCredentialsProvider : NSObject <AWSCredentialsProvider> @property (nonatomic, strong) NSString *accessKey; @property (nonatomic, strong) NSString *secretKey; @property (nonatomic, strong) NSString *sessionKey; @property (nonatomic, strong) NSDate *expiration; - (BFTask *)refresh; @end
// // MyCredentialsProvider.m // #import "MyCredentialsProvider.h" @implementation MyCredentialsProvider @end
Шаг 3
Подключить заголовочные файлы:#import "S3.h" #import "AWSCore.h"
Шаг 4
Написать код для загрузки файла в облачное хранилище Amazon S3:MyCredentialsProvider *theMyCredentialsProvider = [[MyCredentialsProvider alloc] init]; theMyCredentialsProvider.accessKey = @"ASIAI26Q4VETSVHRX4ZQ"; theMyCredentialsProvider.secretKey = @"aCx1FWmZ+b38bhXTANwBgDsAtLfESlYRq3nXgPNu"; theMyCredentialsProvider.sessionKey = @"AQoDYXdzEHwawANKvirYhr5cxiyZyhSLa7GDeSO/0BzNK4NYucSS4+ZdNvvaKKLLvxfxhHJk2D8y5JCge4g/q+Pdv6PQ6BQ1kWR1oJIGz24ePFWKkS4mPkFHVXkykg8AdFtGp/XerEbiTU9paL9ljWmJ4y8cctojXhxEBJNC7jOSgNPh1/IAH4xcl9eEhQSGyxhN58DE0v5V2X29KCK1LZZYXSCn1uOyiH8tdb2wv7zXTQyBRgRHbXxzy8WW5/F/IAN4nUcBuXgL3WGkHAmBLDLcdVg9AFscLQ3VTgcfyAmzi6Xvo762PyCbZkQZj3tNSww7nvN5LBxLzcXVgNq6n327+Ov2okcl0mE8c8VTuomwDypA29nljeuJ+R/Pmqio1zjH/s6yeNXOjB7hRQmnm8gsVm7nYPpdJo0f52U2caxmMst+DdlrGEXgAyGFQAdjNyYuAfRmnAclDFU3X/OBI+Jq92mut6ZecTrtXfuDdfcDMr80aFNsZc2d1s0WqTlqN4xJC3HcfixNaXmQ8m4uHd+LEGifGCJ3EpTYQXJ/miiDnE4khS3yjqxJHNLVWmQgI9R6QW/iXSeaYzBmWTXGGcP0Cye9Cbnmy/wSIJGz6aYF"; AWSServiceConfiguration *theConf = [AWSServiceConfiguration configurationWithRegion:AWSRegionEUCentral1 credentialsProvider:theMyCredentialsProvider]; AWSS3TransferManager *transferManager = [[AWSS3TransferManager alloc] initWithConfiguration:theConf identifier:@"S3"]; AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new]; uploadRequest.bucket = @"example.com/a/b/"; uploadRequest.key = @"My File.txt"; uploadRequest.body = [NSURL fileURLWithPath:@"/Users/Devtype/Documents/My File.txt"]; [[transferManager upload:uploadRequest] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *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. NSLog(@"The file uploaded successfully."); } return nil; }];