GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

CarPlay with SwiftUI LifeCycle

Forums > SwiftUI

Does anyone know how to implement CarPlay within SwiftUI LifeCycle? I always get an error when tried to open in CarPlay.

Application does not implement CarPlay template application lifecycle methods in its scene delegate.

Implementation worsk only when I move

@main
struct MyApp: App {
   ...
 }

to

@main
final class AppDelegate: UIResponder, ObservableObject, UIApplicationDelegate {
...
}

This is not even triggered when I open app in CarPlay from AppDelegate

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {

        if let shortcutItem = options.shortcutItem {
            AppDelegate.shortcutItem = shortcutItem
        }

        if(connectingSceneSession.role == UISceneSession.Role.carTemplateApplication) {
            // CarPlay Scene
            let sceneConfig = UISceneConfiguration(name: "CarPlay", sessionRole: connectingSceneSession.role)
            sceneConfig.delegateClass = CarPlaySceneDelegate.self

            return sceneConfig

        } else {
            // iPhone Scene
            let sceneConfig = UISceneConfiguration(name: "Phone", sessionRole: connectingSceneSession.role)
            sceneConfig.delegateClass = SceneDelegate.self
            return sceneConfig
        }
    }

   

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.