观察到的行为:开始播放音乐文件后,用户进入后台。通过 cast 播放音乐文件几分钟后, session 因 GCKConnectionSuspendReasonNetworkNotReachable
原因暂停,即使发送方设备和 cast 设备都连接到正常工作的 Wi-Fi
连接
预期行为: session 应该继续,因为发送方应用程序具有播放音频的后台功能,而且我们还使用 GCKCastOptions
设置了属性 suspendSessionsWhenBackgrounded
到 NO
。
最佳答案
您可能需要在 GCKRemoteDisplayChannel Class 中检查应用后台运行后的恢复情况
据说,
Normally when an iOS app goes to the background, all network connections are closed and all hardware encoder access is terminated. This effectively means that without special handling a Remote Display session will end upon app backgrounding.
A session can be kept alive in the background by doing the following:
- Initialize the GCKDeviceManager with
initWithDevice:clientPackageName:ignoreAppStateNotifications:
, specifyingYES
as theignoreAppStateNotifications
argument.- Register a background task using
UIApplication
beginBackgroundTaskWithExpirationHandler:
to keep the app running if it is backgrounded for an amount of time controlled by iOS.
有关更多信息,您可能还想查看 Playing media while in the background using AV Foundation on iOS .
关于ios - 由于 "GCKConnectionSuspendReasonNetworkNotReachable",Cast session 暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45918375/