我正在开发一个支持CarPlay的音乐应用程序。有没有一种方法可以识别应用程序是否与Carplay连接/断开?我找不到任何关于这方面的有用文档。
我们非常感谢您提供的任何见解或文档。
发布于 2021-07-20 23:29:27
我和你有同样的问题,没有直接的方法来判断CarPlay是不是从我在文档中读到的东西开始的。我用来检测用户是否启动了CarPlay的一个变通方法是使用MPPlayableContentDelegate的
func playableContentManager(_ contentManager: MPPlayableContentManager, didUpdate context: MPPlayableContentManagerContext)您可以在第一次调用时将布尔值设置为true,这样就可以知道它是否是第一次调用。我知道这个解决方案不是很好,但它对我很有效。例如,当用户第一次打开CarPlay时,我触发了一个跟踪事件来跟踪。我不确定您的用例是什么,因此此解决方案可能不太适合您。
下面是一些代码,请注意布尔值:
class CarPlayContentManager: NSObject, MPPlayableContentDataSource, MPPlayableContentDelegate {
private var isSetup = false
...
func playableContentManager(_ contentManager: MPPlayableContentManager, didUpdate context: MPPlayableContentManagerContext) {
if !isSetup {
// Do some stuff that only happens when CarPlay is setup for the first time
isSetup = true
}
}仅供参考-我不知道如何检测CarPlay何时关闭。
https://stackoverflow.com/questions/68358880
复制相似问题