CPNowPlayingTemplate.shared() - Now having errors?

So I am using the sample code that was provided by Apple in 2020, however it seems that the code is no longer correct.

As I am getting the following error:

Cannot call value of non-function type 'CPNowPlayingTemplate'
Remove '()'


However when I do remove it the app fires up fine, minus the now playing information.

I am wondering what do I need to do to get the now playing information which my iOS app does display, to send over to the CarPlay screen.

I was told - "All you need is this template and then apple does everything in the background."

Clearly that's wrong, because Apple would never make something be so easy.

So I know I am going to have to add buttons, album art extra extra. But I don't know how to go about this, as I normally use SwiftUI.

Code Block
import Foundation
import CarPlay
class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
    
  func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene,
                                  didConnect interfaceController: CPInterfaceController) {
    
    if #available(iOS 14.0, *) {
        let nowPlayingTemplate = CPNowPlayingTemplate.shared
 
        let rateButton = CPNowPlayingPlaybackRateButton() {_ in
            // Change the playback rate!
            
        }
        
        nowPlayingTemplate.updateNowPlayingButtons([rateButton])
      } else {
          // Fallback on earlier versions
      }
      
  }
}

Side note: the sooner Apple allows SwiftUI to take over this the better.

So key questions:

  1. How to print song information on this screen

  2. How to add pause and play button.

I have included my MediaPlayer.swift file so you can see I use  MPNowPlayingInfoCenter





CPNowPlayingTemplate is for your app's now playing UI in CarPlay. You can add and configure custom playback buttons for CarPlay, just as in your partial example.

The album, artist, artwork, and other data appearing in the now playing template comes from the data your app provides to MPNowPlayingInfoCenter. That's the same API you were probably already using to have your app's now playing data appear on the iOS lock screen and in Control Center.

CPNowPlayingTemplate.shared() - Now having errors?
 
 
Q