如何在应用程序转到后台时保持GCKCastSession处于活动状态 [英] How to keep GCKCastSession alive when app goes to background

查看:300
本文介绍了如何在应用程序转到后台时保持GCKCastSession处于活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新的Google Cast SDK for iOS(版本3.1.1.10003),我们的应用程序是远程控制Google Cast设备,例如它改变了音量。当我们的应用程序转到后台时,它也需要这样做。

I'm using latest Google Cast SDK for iOS (version 3.1.1.10003) and our app is remote controlling Google Cast devices, e.g. it changes their volume. It needs to do so also when our app goes to background.

然而, GCKSessionManager 调用 suspendSessionWithReason:当应用程序转到后台时。这就是说,会话将被暂停,因此我们的应用程序无法再控制它。

However, GCKSessionManager invokes suspendSessionWithReason: when the app goes to background. This said, the session will be suspended and thus our app can't control it any longer.

如何制作 GCKSessionManager 当应用程序转到后台时不会暂停会话?

How can I make GCKSessionManager not suspend sessions when apps go to background?

编辑:我在下面提供了一个解决方案,但这不是用户友好的重新连接时显着延迟。

Edit: I'm providing a solution below but that is not user friendly due to significant delays when reconnecting.

推荐答案

在最新的Google Cast SDK中,您可以在选项如下:

In the latest Google Cast SDK, you can set it in the options like so:

let criteria = GCKDiscoveryCriteria(applicationID: kGCKDefaultMediaReceiverApplicationID)
var options = GCKCastOptions(discoveryCriteria: criteria)
options.suspendSessionsWhenBackgrounded = false
GCKCastContext.setSharedInstanceWith(options)

然而,无论如何,会话都会从丢失的网络连接中消失。诀窍是从设备播放空音频文件,使其保持活动状态。愚蠢认为这必须是行业标准。

However, regardless of that, the session dies from a lost network connection. The trick becomes playing an "empty" audio file from the device, which keeps it alive. Stupid to think that this must be the industry standard.

这篇关于如何在应用程序转到后台时保持GCKCastSession处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆