iphone/ipod touch의 내 문서 디렉토리에 해당 링크의 콘텐츠가오고 다운로드 한 후에 문서 디렉토리에서 해당 콘텐츠를 삭제할 수 있다는 요청을 보내 API를 사용하여 서버에서 파일을 다운로드하고 싶습니다. 그런 일을 할 수있는 방법이 있습니까?iphone의 서버 문서 디렉토리에 파일을 다운로드하려면 어떻게해야합니까?
감사 Balraj
iphone/ipod touch의 내 문서 디렉토리에 해당 링크의 콘텐츠가오고 다운로드 한 후에 문서 디렉토리에서 해당 콘텐츠를 삭제할 수 있다는 요청을 보내 API를 사용하여 서버에서 파일을 다운로드하고 싶습니다. 그런 일을 할 수있는 방법이 있습니까?iphone의 서버 문서 디렉토리에 파일을 다운로드하려면 어떻게해야합니까?
감사 Balraj
가장 쉬운 방법은 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];
}
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];
오류 검사를 추가합니다.
문서 폴더 사용에서 파일을 제거하려면 :
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:fileName];
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
이 그것 인 프레임 워크를 경우 아이폰 API입니까? – Ballu
ASIHTTPRequest. 링크는 코드 위의 텍스트에 있습니다. – Ramin