내 온라인 서버에서 오디오 (mp3) 파일을 다운로드하고 내 iPhone 앱의 "Documents"폴더에 저장하여 인터넷에 연결하지 않고 앱에서 재생할 수 있도록 노력했습니다. 다음 코드를 다운로드하여 저장했습니다. 이 코드인터넷에서 오디오 (mp3) 파일을 다운로드하고 iPhone 앱에 저장하는 방법은 무엇입니까?
[NSURLConnection sendAsynchronousRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:fileURL]]
queue: [NSOperationQueue mainQueue]
completionHandler: ^(NSURLResponse *response, NSData *data, NSError *error) {
if(error)
{ }
else
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:path];
[data writeToFile:filePath atomically:YES];
}
}];
나는 MP3 파일을 다운로드 할 수 있으며, 데이터 변수이지만 보인다 [데이터를 writeToFile : 파일 경로를 원자 적 : YES]; 작동 안됨. 문서에 저장하지 않습니다. 이미지 파일의 경우 다음 코드로 작업했습니다.
UIImage *image = [UIImage imageWithData:data];
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
그래서 mp3 파일의 경우 이미지 파일 저장과 비슷한 방법이 있습니까?
감사