音频mp3文件从网址下载

时间:2013-01-21 14:58:12

标签: objective-c ios6

如何从ios 6.0 sdk中大小约5mb的url下载mp3文件我使用jsonparser来获取mp3文件的响应并保存在photolibrary中?

1 个答案:

答案 0 :(得分:1)

NSURL *url = [NSURL URLWithString:@"http://www.pacdv.com/sounds/people_sound_effects/c-c-2.mp3"]; 
NSData *soundData = [NSData dataWithContentsOfURL:url];
NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
NSString *filePath = [documents stringByAppendingPathComponent:@"sound.caf"];
[soundData writeToFile:filePath atomically:YES];