开发者

Download song and store it in iPhone memory

开发者 https://www.devze.com 2023-03-13 22:34 出处:网络
I need require开发者_运维知识库ment for downloads songs and save them in iPhone memory using iphoneSDK, How can I implement to download the song and save to iPhone memory programmatically?Quick one-li

I need require开发者_运维知识库ment for downloads songs and save them in iPhone memory using iphoneSDK, How can I implement to download the song and save to iPhone memory programmatically?


Quick one-liner:

NSData * theMusic = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.domain.com/Music.mp3"]];

EDIT

In addition how to save the NSData object to the local storage.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
if ([theMusic writeToFile:[documentsDirectory stringByAppendingPathComponent:@"theMusic.mp3"] atomically:YES]) {
    // Success !
} else {
    // Error !  
}
0

精彩评论

暂无评论...
验证码 换一张
取 消