본문 바로가기

ios aos 개발/iPhone

[iPhone] 동기식 다운로드 download

반응형
NSURL *url = [NSURL URLWithString:/*파일 다운 받을 url 주소 */];
 
NSMutableURLRequest *thrRequest = [NSMutableURLRequest requestWithURL:url];
NSURLResponse *response;
NSError *error;

 
NSData *getedData = [NSURLConnection sendSynchronousRequest:thrRequest
                                     returningResponse:&response 
error:&error];
    
NSString*_path = [[NSHomeDirectory() stringByAppendingString:@"/Documents/"]
                    stringByAppendingString:[response suggestedFilename]];
     
[getedData writeToFile:_path atomically:YES];