ios - 从锁定的设备启动 CarPlay 音频应用程序时无法启动

标签 ios ios12 carplay

我们有一个音频应用程序,我们想给它添加 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.

我已经实现了 MPPlayableContentDelegateMPPlayableContentDataSource 并且应用选择了音频背景模式。流从网络获取,然后缓存到磁盘。

大家有没有遇到过同样的问题,或者有什么解决办法的提示吗?您知道 Apple 是否有一款支持 CarPlay 的简单工作音频应用程序可供测试吗?

最佳答案

我解决了移动代码以设置和激活 Audio Session 到 AppDelegate 的问题。以前,这是在管理所有流的单例中处理的,即 MPPlayableContentDelegateMPPlayableContentDataSource

将其移至 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/

相关文章:

ios - AvPlayer seekToTime 问题

ios - NSPredicate 用于一对一关系

ios - iOS12系统下APP无法正常显示图片

safari - 应用程序缓存事件 noupdate 在 Safari 浏览器上不会间歇性触发。

ios - 此iPhone运行的是iOS 12.0(16A366),此版本的Xcode可能不支持

swift - carPlay 的新代表

ios - 打开 UIPickerView 非常慢

ios - iOS 中的单行 XML 解析器

ios - 将 CarPlay 添加到 SwiftUI 生命周期应用程序