Add a cancel action to the Media Picker Controller

There is no cancel action in Media Picker Controller.

If I make a wrong select, I cannot undo.


I want a cancel button in Media Picker Controller.

There is a cancel button when making a playlist in Apple Original Music Application.


Is it possible to add a cancel action to Media Picker Controller?

Replies

I find this in documentation


Instance Method mediaPickerDidCancel(_:)


Called when a user dismisses a media item picker by tapping Cancel.


Declaration

optional func mediaPickerDidCancel(_ mediaPicker: MPMediaPickerController)

Parameters

mediaPicker

The media item picker to dismiss.


So there should be a cancel button. Probably it is just not visible.


Could also read this:

https://stackoverflow.com/questions/17552832/why-is-the-cancel-button-in-my-media-picker-not-working

or even better this:

https://stackoverflow.com/questions/28429896/in-uiimagepickercontroller-cancel-button-not-showing

When you have made it possible to select multiple songs, MediaPickerController just has a button to the right of the toolbar that says “Completed.”

If you press this button without selecting any songs, mediaPickerDidCancel (_:) will be called.

However, when one or more songs are selected, pressing this button calls mediaPicker (_:).

In other words, if you select even one song, there is no way to call mediaPickerDidCancel (_:).

I want to display both the Finish and Cancel buttons on the toolbar.

What about unselecting the selected songs ? That should revert to the cancel behavior.

I am in trouble because I can not unselect the selected song.

Did you set allowsPickingMultipleItems to false ?


Instance Property allowsPickingMultipleItems


A Boolean value specifying the default selection behavior for a media item picker.



Declaration

var allowsPickingMultipleItems: Bool { get set }

Discussion

When set to

true
, the media item picker allows the selection of multiple media items. When set to
false
, only a single media item can be selected. The button for dismissing the picker is labeled “Cancel.” when set to
false
and "Done." when set to
true
.


Since I want to be able to select multiple songs, it is true. To make it false and to make a single choice is not what I think.

I want a Cancel button with multiple songs available for selection.

Understood, but API spec seems to show this is not possible, unless you write your own picker subclass.