我想从以下链接下载音频文件

audio file link

我已经尝试过在此网站上发布的其他答案。但是我不想使用ASIHTTPRequest,所以任何人都可以告诉我如何将链接内容下载到我的文档目录中。

最佳答案

好吧,你可以这样写:

//Download data
NSData *data = [NSData dataWithContentsOfURL:<YOUR URL>];

//Find a cache directory. You could consider using documenets dir instead (depends on the data you are fetching)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *path = [paths  objectAtIndex:0];

//Save the data
NSString *dataPath = [path stringByAppendingPathComponent:@"filename"];
dataPath = [dataPath stringByStandardizingPath];
BOOL success = [data writeToFile:dataPath atomically:YES];

10-08 07:45