Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMediaPickerController closes after startup (Swift)

When I click on the cell to open the MPMediaPickerController it opens when it starts up.

gif

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")
}
like image 503
B2Fq Avatar asked Mar 07 '23 15:03

B2Fq


1 Answers

Please add this in your info.plist

<key>NSAppleMusicUsageDescription</key>
<string>$(app Name) uses music</string>

It works for me.

like image 148
PPL Avatar answered Mar 17 '23 00:03

PPL