Download song and store it in iPhone memory
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 !  
}
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论