[英]How to download a file from AWS S3 and access it in iOS
我瀏覽了所有這個論壇和網絡,找不到任何可以幫助我的東西。 我在S3服務器上存儲了一個文本文件,我需要將其下載到我的iOS應用中並以字符串形式讀取文件。 我可以訪問服務器並打開輸出流以保存文件。 當我嘗試立即訪問該文件時,該文件不存在。 如果有人准確地做到了這一點,並且可以帶我逐步解決,那將是非常棒的,但是任何事情都會有所幫助
ViewController.h:
@interface ViewController : UIViewController <NSURLSessionDelegate>
@end
ViewController.m:
- (void)downloadMethod
{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"yourFileURLString"]];
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration ephemeralSessionConfiguration];
defaultConfigObject.requestCachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:[NSOperationQueue mainQueue]];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if (error == nil && data != nil)
{
NSString *theString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"String is: %@",theString);
}
}];
[dataTask resume];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.