MPMediaLibrary not working properly - iOS 14 beta

I'm using the MPMediaLibrary's addItem(withProductID:completionHandler:) function:

https://developer.apple.com/documentation/mediaplayer/mpmedialibrary/1621278-additem

but the completion is never called, no matter where I call it in my code, regardless if the item was or wasn't already in the user's library. Has the API changed or is this a beta issue?

Accepted Reply

I am having the same issue, it worked fine with an older beta, but always hangs with beta 7 (I didn't update for a while, so I don't know when it started).

Replies

I am having the same issue, it worked fine with an older beta, but always hangs with beta 7 (I didn't update for a while, so I don't know when it started).
Official release of iOS 14 is out and this still isn't fixed.
I still have the issue with iOS 14.0.1.
Is the bug still happening on iOS 14.1?
Seems to still be a problem in iOS 14.1 as I outlined in this post:
https://developer.apple.com/forums/thread/664336

Has anyone filed a bug report?
Is everyone still experiencing this in 14.2? Is there a way to speak with Apple engineers about these sorts of issues?
I am facing the same problem.
Here we can submit this bug:
https://developer.apple.com/bug-reporting/

Just installed iOS 14.3 beta 3 and this bug is still there. Is there anyone watching this thread that can offer any help or additional information?
Hello @RobertManea,

Thank you very much for reporting this issue.

We will investigate this regression.

Thanks again for your feedback.

Best regards, 
I just installed iOS 14.3 RC and this bug is still there. Very frustrating! If anyone knows anything about the status of this bug could chime in, it would be great. An outstanding bug for more than 3 months is troubling.
Still a bug in iOS 14.4 first beta (12/16/2020)

Same here, using iOS 14.0.1 . I had to use a predicate along with the persistentId of the song and use the function .add() instead of .addItem()

let query = MPMediaQuery.songs()
let pred = MPMediaPropertyPredicate(value: "4810553823034020895" , forProperty: MPMediaItemPropertyPersistentID)
query.addFilterPredicate(pred)
let songs = query.items! as [MPMediaItem]
  
mediaPlaylist.add(songs, completionHandler: { (error) in
      guard error == nil else {
         fatalError("An error occurred while adding an items to the playlist: \(error!.localizedDescription)")
       }
 
       print("SONGs \(identifier) ADDED")
}

Noticed only downloaded songs could be added to the playlist. Otherwise the function won't add the song to the playlist.
Hope that help somehow.

@davenorfleet even in 14.4 beta??? Damn, that sucks.

@JoeKun any updates?
Still a bug in iOS 14.4 Beta 2 - 1/13/2021 - I was hopeful 2021 would bring a fix.
And if anyone who has any influence on getting this fixed needs a little nudge, please notice that this bug is over 4 months old.
iOS 14.4 RC is out. This bug is still present. I'm going to remove the feature from my apps that used this API. Not sure what's going on at the Bug Repair Shop, but my reputation as a developer can't wait any longer. 

For those in the same boat, here's what I'm doing to replace the basic function, inspired by pochimen's post. It's messy but at least it works. (Something I'm a bit embarrassed to be a part of.)

Using the productID that should be passed to the black hole formerly known as 
Code Block
[MPMediaLibrarydefaultMediaLibrary] addItemWithProductID:

use 
Code Block
MPMusicPlayer setQueueWithStoreIDs:productID
musicPlayer.play

Wait for track to start playing by polling 
Code Block
musicPlayer.nowPlayingItem 

to be sure it's set, 
Code Block
musicPlayer.nowPlayingItem.playbackDuration 

to be sure it has a value and 
Code Block
musicPlayer.currentPlaybackTime > 0.1 

to be sure the item has started playing.
(I know this seems overkill, but I've seen examples of one or two of these conditions being met yet the other(s) do not return a value.)

Once above conditions are met, find or create a playlist for my app and add the track with 
Code Block
[playlist addMediaItems:nowPlayingMediaItem completionHandler:

Not too pretty, but gets the job done. Kinda like me ;-)