您的位置:首页 > 其它

下载

2016-02-25 17:02 204 查看
2. /Documents/。使用该路径放置关键数据,也就是不能通过App重新生成的数据。该路径可通过配置实现iTunes共享文件。可被iTunes备份。(现在保存在该路径下的文件还需要考虑iCloud同步)

3. /Library/。该路径下一般保存着用户配置文件。可创建子文件夹。可以用来放置您希望被备份但不希望被用户看到的数据。该路径下的文件夹,除Caches以外,都会被iTunes备份。

4. /tmp/。使用该路径保存临时文件。App应该删除那些不再被使用的文件,系统也会在App关闭后删除残留文件。该路径下的文件不会被iTunes备份。

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSPicturesDirectory, NSUserDomainMask, YES);
NSString* _filePath = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"filename.pdf",];
NSString *filePath = [_filePath stringByAppendingPathComponent:fileName];
NSString *urlStr =@"http://loadurlStr";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]];
AFURLConnectionOperation *operation = [[AFURLConnectionOperation alloc]initWithRequest:request];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:YES];
[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
NSLog(@"%f",totalBytesRead/(float)totalBytesExpectedToRead);
}];
[operation setCompletionBlock:^{
//用webview打开下载下来的文件
NSURL *url = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20];
UIWebView *web = [[UIWebView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:web];
[self.view bringSubviewToFront:web];
[web loadRequest:request];
}];
[operation start];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: