2009-10-06 5 views

답변

3

가장 쉬운 방법은 ASIHTTPRequest를 사용하는 것입니다 및 수행

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; 
[request setDelegate:self]; 
[request setDownloadDestinationPath:@"{path to file in documents folder}"]]; 
[request startAsynchronous]; 

... 

- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
// Downloaded file is ready for use 
} 

- (void)requestFailed:(ASIHTTPRequest *)request 
{ 
// Download failed. This is why. 
NSError *error = [request error]; 
} 
+0

이 그것 인 프레임 워크를 경우 아이폰 API입니까? – Ballu

+0

ASIHTTPRequest. 링크는 코드 위의 텍스트에 있습니다. – Ramin

3
NSData *data = [NSData dataWithContentsOfURL:@"http://site.com/filename"]; 

NSArray *docList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentDir = [docList objectAtIndex:0]; 
NSString *documentPath = [historicDocumentDir stringByAppendingPathComponent:@"filename"]; 

[data writeToFile:documentPath atomically:NO]; 

오류 검사를 추가합니다.

3

문서 폴더 사용에서 파일을 제거하려면 :

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:fileName]; 
[[NSFileManager defaultManager] removeItemAtPath:path error:nil]; 
관련 문제