分类: iOS平台
2013-11-14 15:53:24
+(void)download:(NSString *)strOfURL andMusicName:(NSString *)musicName
{
NSString *strOfURL = [NSString stringWithFormat:@"%@",strOfURL];
NSURL *URL = [NSURL URLWithString:strOfURL];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
/* 下载的数据 */
if (data != nil)
{
NSLog(@"下载成功");
/*存放路径*/
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *path=[[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp3",musicName]];
if ([data writeToFile:path atomically:YES])
{
NSLog(@"保存成功.");
}
else
{
NSLog(@"保存失败.");
}
}
else
{
NSLog(@"%@", error);
}