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.
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:
How to print song information on this screen
How to add pause and play button.
I have included my MediaPlayer.swift file so you can see I use MPNowPlayingInfoCenter
MediaPlayer.swift - https://developer.apple.com/forums/content/attachment/0caa76cd-53d3-439c-9a86-37703dc20348
1
0
1.9k