I'm working on adding CarPlay support for our audio app.
When returning instances of MPContentItem in response to the contentItemAtIndexPath: method, sometimes I need to fetch the artwork asynchronously (eg: network fetch). What is the recommended way to do this with the CarPlay API?
What I've tried so for is to return a populated instance of MPContentItem right away and at the same time trigger a fetch for the artwork. On completion of the fetch, I update the artwork property of the same instance that I previously returned, wrapping it with beginUpdates and endUpdates calls. This doesn't seem to work consistently, sometimes the art updates, other times it doesn't update. Usually when I scroll the item out of bounds and back in, it uses the correct art.
I've tested this approach both in a Simulator and in a car with CarPlay.
What is the correct way to perform these updates?
Thanks!
You should fetch image data the same way you would in an iOS app.
Once you have your images you will want to update your MPContentItem instance. From our documentation :
Update an
MPContentItem
object by changing its properties during runtime or by creating a new MPContentItem
object with new property values, but with the same identifier as the MPContentItem
object to be changed. Use the beginUpdates()
and endUpdates()
methods found in MPPlayableContentManager
to update several MPContentItem
objects at once.