누군가 파일을 재생하는 대신 파일을 다운로드하려는 경우 해당 기능이나 방법이 사용됩니다.URL에서 mp3 파일을 다운로드하는 방법
파일을 다운로드하고 싶습니다. 이 개념에 대해 몇 가지 예를 들어 주시거나 저에게이 아이디어에 대해 약간의 아이디어를 주시겠습니까?
대단히 감사합니다.
누군가 파일을 재생하는 대신 파일을 다운로드하려는 경우 해당 기능이나 방법이 사용됩니다.URL에서 mp3 파일을 다운로드하는 방법
파일을 다운로드하고 싶습니다. 이 개념에 대해 몇 가지 예를 들어 주시거나 저에게이 아이디어에 대해 약간의 아이디어를 주시겠습니까?
대단히 감사합니다.
다음과 같이 요청을 보내십시오.
NSURL *url = [NSURL URLWithString:[fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setValue:[NSString stringWithFormat:@"bytes=%ld-",0] forHTTPHeaderField:@"Range"];
[theRequest addValue: @"pdf" forHTTPHeaderField:@"Content-Type"];
[theRequest setHTTPMethod:@"POST"];
webData = [[NSMutableData alloc] init];
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
구현 다음 방법 ...
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [webData appendData:data]; }
-(void)connectionDidFinishLoading:(NSURLConnection )connection {
/******CODE FOR WRITING FILE*************/ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [paths objectAtIndex:0];
NSString *directoryPath = [documentPath stringByAppendingPathComponent:[MAIN_DIRECTORY stringByAppendingPathComponent:fileDate]];
[[NSFileManager defaultManager] createDirectoryAtPath:directoryPath withIntermediateDirectories:NO attributes:nil error:nil];
[webData writeToFile:fileName atomically:YES];
}