how can I know if I am connected to carplay

I'm doing my app that need to know if iphone connected to carplay, and do somthing before that.


I've seached everywhere and found some method, but seems every method got problem.


method1.

if your app is music type and using key "com.apple.developer.playable-content"

you can get notify when connect/disconnect from "MPPlayableContentDelegate ->playableContentManager ->context.endpointAvailable"

But my concern:

A. my app is voip type using key "com.apple.developer.carplay-calling", if I using MPPlayableContentDelegate, seems not properly.

B. does MPPlayableContentDelegate on used in carplay? Does any other device connected to iphone will receive this notify?


method2.

check the "AVAudioSession.sharedInstance().currentRoute.outputs.first" when receive method1 notify.

But only can get right value when audio file is playing. if no audio playing, it always get the iphone self instead of carplay.


method3.

using "EAAccessoryManager.shared().connectedAccessories", it needs manually set the info.plist supported protocal in advance.

so if I cant set the right protocal for every car type, I cant get the accessories.


Anyone can help on this issue, thanks.