下载

来源:互联网 发布:金融行业使用软件 编辑:程序博客网 时间:2024/04/30 07:44
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];
0 0
原创粉丝点击