
- (voID)downloadSingledocument:(NSURL *)url{ [pdfData release]; pdfData = [[NSMutableData alloc] init]; NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; [req addValue:@"Basic **************=" forhttpheaderFIEld:@"Authorization"]; downloadConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES];}- (voID)connection:(NSURLConnection *)conn dIDReceiveData:(NSData *)data{ NSLog(@"Connection dID receive data"); [pdfData appendData:data];} 在connectionDIDFinishLoading上,我想将下载的pdf文件保存到documents目录中的文件系统,文件名与服务器上的文件名相同.
最好的方法是什么?
- (voID)connection:(NSURLConnection *)connection dIDReceiveResponse:(NSURLResponse*)response{ filepath = [[NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:save_name]; [[NSfileManager defaultManager] createfileAtPath:filepath contents:nil attributes:nil]; file = [[NSfileHandle fileHandleForUpdatingAtPath:filepath] retain];// Here file is object of NSfileHandle and its declare in .h file [file seekToEndOffile];}- (voID)connection:(NSURLConnection *)connection dIDReceiveData:(NSData *)data{ [file seekToEndOffile]; [file writeData:data];}- (voID)connectionDIDFinishLoading:(NSURLConnection*)connection { [file closefile];// After you download your data. you can copy your data from here to filesystem. and remove from here } 总结 以上是内存溢出为你收集整理的iphone – 如何将下载的数据保存到设备的文件系统全部内容,希望文章能够帮你解决iphone – 如何将下载的数据保存到设备的文件系统所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)