In: Computer Science
CarPlay is the smart and safe way by the help of which we can use our Iphon in the car.
It provides all the functionalities and features that are required with Iphone while driving and make them visible on the car's built in display.
In this we can do the coding and develop applications for this we require Xcode and an Apple Developer Program account.
All the applications developed using this are adjustable on all the screens Iphone, Macbook, Apple Watch etc.
In this several templates are provided which we can use to develop the applications:
Code to generate a list:
import CarPlay
let item = CPListItem(text: “My title", detailText: “My subtitle")
item.listItemHandler = {
item, completion, [weak self] in // Start playback asynchronously…
self.interfaceController.pushTemplate(CPNowPlayingTemplate.shared(), animated: true) completion()
}
let section = CPListSection(items: [item])
let listTemplate = CPListTemplate(title: "Albums", sections: [section])
self.interfaceController.pushTemplate(listTemplate, animated: true)
Code for now playing template:
import CarPlay
class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController) {
let nowPlayingTemplate = CPNowPlayingTemplate.shared()
let rateButton = CPNowPlayingPlaybackRateButton() { // Change the playback rate! }
nowPlayingTemplate.updateNowPlayingButtons([rateButton]) } }