Is there a way to detect in an app if the phone was connected/disconnected to/from the car using Carplay? Can't seem to find any documentation regarding it. I'm thinking of some system event like that I could monitor.
Asked
Active
Viewed 2,532 times
1 Answers
1
Have you followed these steps?
- Add corresponding record to your project's Entitlements file:
com.apple.developer.carplay-maps
type ofBoolean
with valueYES
- Request from Apple corresponding permission
- Make your AppDelegate confirm to
CPApplicationDelegate
protocol Implement the next methods:
/** The CarPlay screen has connected and is ready to present content. Your app should create its view controller and assign it to the @c rootViewController property of this window. @note It is the responsibility of the delegate to maintain a reference to the interface controller beyond the scope of this method. */ - (void)application:(UIApplication *)application didConnectCarInterfaceController:(CPInterfaceController *)interfaceController toWindow:(CPWindow *)window; /** The CarPlay screen has disconnected. */ - (void)application:(UIApplication *)application didDisconnectCarInterfaceController:(CPInterfaceController *)interfaceController fromWindow:(CPWindow *)window;
Please, check this Documentation link and this WWDC 2018 Carplay Session

Aleksey Potapov
- 3,683
- 5
- 42
- 65
-
2Note that this only applies to CarPlay navigation apps. Audio apps should not need to take care about that connection state. – DrMickeyLauer Feb 05 '19 at 16:28
-
@DrMickeyLauer Im building out an Audio app, is there an equivalent call for Audio apps that you are aware of? Im trying to find a good place to load my data/ – MiMo Apr 18 '19 at 21:22
-
@MiMo Nothing prevents you from doing it unconditionally in `applicationDidFinishLaunching`, if there is no CarPlay, it will just not be used. Then again, if you absolutely insist, a worthwhile approach may be listening for Audio Output Route changes – perhaps this will be triggered on connection/disconnection of CarPlay. – DrMickeyLauer Apr 20 '19 at 12:05
-
@DrMickeyLauer loading my data includes a call to the api, parsing, I'd rather not do it on every applicationDidFinishLaunch since the app without CarPlay never needs that data at applicationDidFinishLaunch. – MiMo Apr 20 '19 at 16:23
-
1@Mimo: I see, and I agree. Please open a feature wish against the Apple bug tracker, CarPlay Audio apps should deserve proper (dis)connection callbacks same as Map apps. – DrMickeyLauer Apr 21 '19 at 19:15
-
It does appear that you do need com.apple.developer.carplay-maps in the entitlement file in order for the CPApplicationDelegate methods to be called, but this is indeed intended for maps apps only. It is indeed unfortunate there aren't similar callbacks for Audio apps. – Chris Livdahl May 14 '19 at 01:00