I am developing two CarPlay apps where one is navigation app and other is Food Ordering app.
My requirement is to launch navigation app from Food Ordering app after successfully placing an order to show navigation to restaurant.
I tried it by handling URL schemes in sample CarPlay navigation app provided by Apple.
Here is code which I implemented in Food order app:
let coastalHooks = "CoastalRoads://"
if let coastalUrl = URL(string: coastalHooks) {
if UIApplication.shared.canOpenURL(coastalUrl) {
UIApplication.shared.openURL(coastalUrl)
}
}
As In CoastalRoads app there are two scene delegates are handled one is 'LoggerWindowSceneDelegate', which is for main phone app and other is 'TemplateApplicationSceneDelegate', which is for CarPlay but didn't found anything to launch specific scene of CarPlay.
Here is link where from I downloaded sample CarPlay app:
https://developer.apple.com/documentation/carplay/integrating_carplay_with_your_navigation_app
My requirement is to launch navigation app from Food Ordering app after successfully placing an order to show navigation to restaurant.
I tried it by handling URL schemes in sample CarPlay navigation app provided by Apple.
Here is code which I implemented in Food order app:
let coastalHooks = "CoastalRoads://"
if let coastalUrl = URL(string: coastalHooks) {
if UIApplication.shared.canOpenURL(coastalUrl) {
UIApplication.shared.openURL(coastalUrl)
}
}
As In CoastalRoads app there are two scene delegates are handled one is 'LoggerWindowSceneDelegate', which is for main phone app and other is 'TemplateApplicationSceneDelegate', which is for CarPlay but didn't found anything to launch specific scene of CarPlay.
Here is link where from I downloaded sample CarPlay app:
https://developer.apple.com/documentation/carplay/integrating_carplay_with_your_navigation_app
I think that you can solve it by referring to the following thread.
You can launch another carplay app by using CPTemplateApplicationScene.
https://developer.apple.com/forums/thread/128945
My situation, I implement the following in CarPlaySceneDelegate.
I can launch another CarPlay app using URL scheme like this.
Example code (Launch iOS map or google map in CarPlay):
You can launch another carplay app by using CPTemplateApplicationScene.
https://developer.apple.com/forums/thread/128945
My situation, I implement the following in CarPlaySceneDelegate.
I can launch another CarPlay app using URL scheme like this.
Example code (Launch iOS map or google map in CarPlay):
Code Block language import CarPlay class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate { ... var cpTemplateApplicationScene : CPTemplateApplicationScene? ... // CarPlay connected func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController) { ... self.cpTemplateApplicationScene = templateApplicationScene ... // Call the following by some kind of trigger. self.launchmap(<desination latitude>, <desination longtitude>, carplay: true) ... } // Lanch map app function func launchmap(latitude: String, longtitude: String, carplay : Bool = true) { let urlString: String! if UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) { urlString = "comgooglemaps://?&daddr=\(latitude),\(longtitude)&directionsmode=driving" } else { urlString = "http://maps.apple.com/?daddr=\(latitude),\(longtitude)&dirflg=d" } if let url = URL(string: urlString) { if (carplay) { self.cpTemplateApplicationScene?.open(url, options: nil, completionHandler: { (Void) in print("completed!")}) } else { UIApplication.shared.open(url) } } } ... }