Search code examples
swiftxcodecarplay

CarPlay: mpContentItem artwork not shown


I've build a radio-app with CarPlay enabled. It worked great but somehow the artwork of a mpContentItem is not shown anymore. Please help me out here ;)

enter image description here

I read that there are maximum sizes for the images.

But still I'm not able to get the images back again. Both for the tabbar artwork and the item artwork (the logo of the radiostation). My code for creating a tabbar item:

func contentItem(at indexPath: IndexPath) -> MPContentItem? {

  let mpContentItem = MPContentItem()
        
  mpContentItem.title = radioStation[0]
  mpContentItem.subtitle = radioStation[1]
  mpContentItem.isStreamingContent = true
  mpContentItem.isPlayable = true
                                         
  let radioImage = loadImage(named: radioStation[3])
  let radioArtwork = MPMediaItemArtwork.init(boundsSize: radioImage.size, requestHandler: { (size) -> UIImage in return radioImage})

  mpContentItem.artwork = radioArtwork
        
  return mpContentItem

}

Can someone help me out here?

Update: this is the loadImage function

func loadImage (named: String) -> UIImage {
                
        if let confirmedImage = UIImage(named: named) {
            
            return confirmedImage
            
        } else {
            
            return UIImage(named: "defaultImage.png")!
            
        }
        
    }

Update: I use this code for the tabbar items:

let mpContentItem = MPContentItem(identifier: "landelijk")
mpContentItem.title = "landelijk"
mpContentItem.isContainer = true
mpContentItem.isPlayable = false
             
let radioImage = UIImage(named: "pijltjesCarplay")!
let radioArtwork = MPMediaItemArtwork.init(boundsSize: radioImage.size, requestHandler: { (size) -> UIImage in return radioImage.imageWith(newSize: size)})

mpContentItem.artwork = radioArtwork
            

return mpContentItem

See also my image asset screenshot:

enter image description here


Solution

  • I finally stepped over to the new CarPlay framework with help of Fruitcode (thanks a lot). Everything works fine now.