Chinaunix首页 | 论坛 | 博客
  • 博客访问: 307014
  • 博文数量: 53
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 325
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-14 22:50
文章分类

全部博文(53)

文章存档

2014年(15)

2013年(38)

我的朋友

分类: 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);

    }

}



阅读(351) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~