George Lee George Lee - 1 year ago 137
Swift Question

How Do I Present a Music Library With a View Controller for a MPMediaPickerControllerDelegate using Swift 3 iOS10?

I am trying to follow a recent post on using a

to present a music selection list.

The tutorial is found at this URL:

I am using this code:

import UIKit
import MediaPlayer

class ViewController: UIViewController, MPMediaPickerControllerDelegate {

var mediapicker1: MPMediaPickerController!

override func viewDidLoad() {

let mediaPicker: MPMediaPickerController = MPMediaPickerController.self(
mediaPicker.allowsPickingMultipleItems = false
mediapicker1 = mediaPicker
mediaPicker.delegate = self
self.presentViewController(mediapicker1, animated: true, completion: nil)

However I have found that the:

self.presentViewController(mediapicker1, animated: true, completion: nil)

does not work. Unfortunately, Swift 3's suggested automatic solution does not work either:

self.present(mediapicker1, animated: true, completion: nil)

Furthermore, the iOS 10 Beta Release Notes, found at:

says on page 10 of 18,

An MPMediaPickerController object may not display as expected.

I have spent a great deal of time looking to solve this issue on my own with no success.

Any suggestions?

Answer Source

Go through the steps:

  1. Add 'NSAppleMusicUsageDescription' to your Info.plist for the privacy authority.
  2. Make sure your Music app is available in your iPhone. It will not work in the simulator.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download