When I click on the cell to open the MPMediaPickerController it opens when it starts up.
class MediaViewController: UITableViewController, MPMediaPickerControllerDelegate
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 2 {
if indexPath.row == 0 {
let mediaPicker = MPMediaPickerController(mediaTypes: MPMediaType.anyAudio)
mediaPicker.delegate = self
mediaPicker.prompt = "Select song"
mediaPicker.allowsPickingMultipleItems = false
self.present(mediaPicker, animated: true, completion: nil)
}
}
}
func mediaPicker(_ mediaPicker: MPMediaPickerController, didPickMediaItems mediaItemCollection:MPMediaItemCollection) -> Void {
}
func mediaPickerDidCancel(_ mediaPicker: MPMediaPickerController) {
dismiss(animated: true, completion: nil)
print("MPMediaPickerController - Cancel")
}
Please add this in your info.plist
<key>NSAppleMusicUsageDescription</key>
<string>$(app Name) uses music</string>
It works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With