0
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:strFileUrl]]; //strFileURL is url of my video/image
NSURLConnection *conection = [[[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO] autorelease];
[conec start];
[request release];

使用上面的代码,我正在创建 URL 连接以从服务器下载数据。

strFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:strFileName];

使用上面的代码我可以获取文件的路径来保存数据,但是在上面的代码中我不知道如何获取strFileName(最后在上面的代码中)或者请任何人帮助我如何将数据保存到我的文档目录之后从服务器获取数据。提前感谢大家。

4

1 回答 1

1
//Capturing server response

 NSData* result = [NSURLConnection sendSynchronousRequest:request  returningResponse:&response error:&error];

 NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];   
 NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[(NSURLResponse *)response suggestedFilename]]; 


 NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager createFileAtPath:fullPath contents:result attributes:nil];
于 2013-02-15T13:44:44.523 回答