Trying to make a file copy from MPMediaPickerController but …?

旧时模样 提交于 2019-12-20 07:07:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!