我正在从服务器下载 pdf 文档:
- (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 目录中的文件系统,文件名与服务器上的文件名相同。最好的方法是什么?