9

我们有一个音频应用程序,我们想将 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应用程序选择了音频背景模式。流是从网络获取的,然后缓存到磁盘。

每个人都遇到过同样的问题或有任何解决方法的提示吗?你知道苹果是否有一个简单的、支持 CarPlay 的音频应用程序来测试吗?

4

1 回答 1

1

我解决了将代码移动到设置和激活音频会话到AppDelegate. 以前,这是在管理所有流的单例中处理的,并且是MPPlayableContentDelegateand 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 条目以允许 HTTP ( NSExceptionAllowsInsecureHTTPLoads)。之前只有Allow Arbitrary Loadsstetted 太真实了。不知道这是否有帮助。

于 2018-11-13T15:59:04.787 回答