以编程方式将mp3文件保存到ios手机

以编程方式将mp3文件保存到ios手机,ios,xcode,swift,Ios,Xcode,Swift,在我的应用程序中,我显示了Ressource中的mp3文件列表,我想让用户能够下载这些文件,为此我使用了类似的函数/方法 func downloadClicked(sender: UIButton){ UISaveVideoAtPathToSavedPhotosAlbum(NSBundle.mainBundle().pathForResource("level-complete", ofType:"mp3")!, nil, nil, nil); } 我也不例外,但我在我的本

在我的应用程序中,我显示了
Ressource
中的
mp3
文件列表,我想让用户能够
下载这些文件,为此我使用了类似的
函数/方法

func downloadClicked(sender: UIButton){


       UISaveVideoAtPathToSavedPhotosAlbum(NSBundle.mainBundle().pathForResource("level-complete", ofType:"mp3")!, nil, nil, nil);

}
我也不例外,但我在我的本地库中找不到这个
**mp3**
(我使用应用程序vlc检查它和itunes)

请问我怎样才能做到这一点

希望这有助于:

参考:


我认为您无法将音频保存到相册。
NSData *dataMp3 = [NSData dataWithContentsOfURL: localMp3File.url];

//Get path directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

//Create Download directory
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Mp3"];
[[NSFileManager defaultManager] documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil];

NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"your-file-name"];

[dataMp3 writeToFile:filePath atomically:YES];