我们有一个音频应用程序,我们想给它添加 CarPlay。该应用基本上有一个广播流列表,用户可以选择播放哪个。
如果我在连接到 CarPlay 时从手机启动应用程序,或者如果我从 CarPlay 启动它并且设备已解锁,一切都很好。 If the device is locked the app starts, I can see the elements on the list in CarPlay but when one of that is selected nothing happens.
我已经实现了 MPPlayableContentDelegate
、MPPlayableContentDataSource
并且应用选择了音频背景模式。流从网络获取,然后缓存到磁盘。
大家有没有遇到过同样的问题,或者有什么解决办法的提示吗?您知道 Apple 是否有一款支持 CarPlay 的简单工作音频应用程序可供测试吗?
最佳答案
我解决了移动代码以设置和激活 Audio Session 到 AppDelegate
的问题。以前,这是在管理所有流的单例中处理的,即 MPPlayableContentDelegate
和 MPPlayableContentDataSource
。
将其移至 AppDelegate 解决了问题,但我仍然不知道为什么:
func startAudioSession() {
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(.playback, mode: .default)
try audioSession.setActive(true, options: AVAudioSession.SetActiveOptions.notifyOthersOnDeactivation)
} catch let error as NSError {
print("Unable to activate audio session: \(error.localizedDescription)")
}
}
我还在 Info.plist 的 App Transport Security 条目中添加了 stremaming 的域以允许 HTTP (NSExceptionAllowsInsecureHTTPLoads
)。之前只有 Allow Arbitrary Loads
太正确了。不知道有没有帮助。
关于ios - 从锁定的设备启动 CarPlay 音频应用程序时无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53190068/