I’m going through one situation the place I’ve created a automotive play scene delegate file but it surely by no means will get executed.
Right here is my code for the app
@primary
struct FredScannerProApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var physique: some Scene {
WindowGroup {
ContentView()
}
}
}
Right here is app delegate file
class AppDelegate: UIResponder, UIApplicationDelegate {
func software(_ software: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
do
{
strive AVAudioSession.sharedInstance().setCategory(AVAudioSession.Class.playback)
strive AVAudioSession.sharedInstance().setActive(true)
}
catch
{
print(error)
}
// This may allow to point out nowplaying controls on lock display screen
software.beginReceivingRemoteControlEvents()
return true
}
// MARK: UISceneSession Lifecycle
func software(_ software: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, choices: UIScene.ConnectionOptions) -> UISceneConfiguration {
if (connectingSceneSession.position == UISceneSession.Function.carTemplateApplication) {
let scene = UISceneConfiguration(identify: "CarPlaySceneConfiguration", sessionRole: connectingSceneSession.position)
scene.delegateClass = CarPlaySceneDelegate.self
return scene
} else {
return UISceneConfiguration(identify: "Default Configuration", sessionRole: connectingSceneSession.position)
}
}
func software(_ software: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}
func software(_ software: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Known as when the person discards a scene session.
// If any classes have been discarded whereas the appliance was not working, this will probably be referred to as shortly after software:didFinishLaunchingWithOptions.
// Use this technique to launch any sources that have been particular to the discarded scenes, as they won't return.
}
}
Right here is information plist file
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>CPTemplateApplicationSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneClassName</key>
<string>CPTemplateApplicationScene</string>
<key>UISceneConfigurationName</key>
<string>CarPlaySceneConfiguration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).CarPlayDelegate</string>
</dict>
</array>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
Right here is carplayscenedelegate file
class CarPlayDelegate: UIResponder {
var carPlaymanager = CarPlaySceneDelegate()
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, choices connectionOptions: UIScene.ConnectionOptions) {
// Use this technique to optionally configure and connect the UIWindow `window` to the supplied UIWindowScene `scene`.
// If utilizing a storyboard, the `window` property will mechanically be initialized and hooked up to the scene.
// This delegate doesn't indicate the connecting scene or session are new (see `software:configurationForConnectingSceneSession` as an alternative).
if scene is CPTemplateApplicationScene, session.configuration.identify == "CarPlaySceneConfiguration" {
// MemoryLogger.shared.appendEvent("Template software scene will join.")
print("Linked")
}
}
func sceneDidDisconnect(_ scene: UIScene) {
// Known as because the scene is being launched by the system.
// This happens shortly after the scene enters the background, or when its session is discarded.
// Launch any sources related to this scene that may be re-created the subsequent time the scene connects.
// The scene could re-connect later, as its session was not neccessarily discarded (see `software:didDiscardSceneSessions` as an alternative).
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Known as when the scene has moved from an inactive state to an energetic state.
// Use this technique to restart any duties that have been paused (or not but began) when the scene was inactive.
}
func sceneWillResignActive(_ scene: UIScene) {
// Known as when the scene will transfer from an energetic state to an inactive state.
// This will happen as a result of momentary interruptions (ex. an incoming telephone name).
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Known as because the scene transitions from the background to the foreground.
// Use this technique to undo the adjustments made on getting into the background.
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Known as because the scene transitions from the foreground to the background.
// Use this technique to avoid wasting knowledge, launch shared sources, and retailer sufficient scene-specific state info
// to revive the scene again to its present state.
}
}
extension CarPlayDelegate : CPTemplateApplicationSceneDelegate{
/// Connects the basis template to the CPInterfaceController.
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController) {
self.carPlaymanager.join(interfaceController)
}
// CarPlay disconnected
personal func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didDisconnect interfaceController: CPInterfaceController) {
self.carPlaymanager.disconnect()
}
}
however someway it is not attaching carplay occasion
i do not know what is going on on? If somebody may assist me on this. I actually respect it.
Additionally, Let me know if you need demo undertaking, I’ll present similar,
Thanks