问题
I am accessing some audio files from my iTunes library using MPMediaPickerController
, inside an iOS application.
I would like to copy those files into my app Document Directory for local processing. But I am wondering if this is meant to be possible.
Here is the relevant code that I use:
func mediaPicker(_ mediaPicker: MPMediaPickerController,
didPickMediaItems mediaItemCollection: MPMediaItemCollection) {
guard let theMediaItem = mediaItemCollection.items.first else {return}
let newFileName = "abcd456kx82",
newFileURL = theDocumentsDirectory().appendingPathComponent(newFileName)
do {try FileManager.default.copyItem(at: theMediaItem?.assetURL, to: newFileURL)
} catch {
print("Error in \(#function) \(url.path): \(error.localizedDescription)")
}
.... useful, but irrelevant code ....
}
When I run this code, this is an example of what I get in the debugging console:
Error in .... /item.mp3: The file “item.mp3” couldn’t be opened because URL type ipod-library isn’t supported.
Am I doing it the wrong way? Or am trying to do what I am not supposed to do?
来源:https://stackoverflow.com/questions/57987133/trying-to-make-a-file-copy-from-mpmediapickercontroller-but