【发布时间】:2018-09-11 11:21:37
【问题描述】:
我正在使用googlecast sdk iOS 4.0.2 版本在同一wifi网络下寻找可投射设备,iOS版本为10.0或以上。
我创建了一个单例,并注册了监听器,当第一次找到设备时成功调用它。 之后就不能再调用了。
因为我不需要自动启动,所以下面是我初始化castcontext的代码。
let criteria = GCKDiscoveryCriteria.init(applicationID: kGoogleCastApplicationID)
let options = GCKCastOptions.init(discoveryCriteria: criteria)
options.disableDiscoveryAutostart = false
options.stopReceiverApplicationWhenEndingSession = true
GCKCastContext.setSharedInstanceWith(
我将其设置为 false 是因为 sdk 中有以下注释。
/**
* A flag indicating whether the discovery of Cast devices should start automatically at
* context initialization time. If set to <code>NO</code>, discovery can be started and stopped
* on-demand by using the methods GCKDiscoveryManager::startDiscovery and
* GCKDiscoveryManager::stopDiscovery.
*
* @since 3.4
*/
这是我开始和停止它的方法。
开始
func startDiscovery() {
if !discoveryManager.discoveryActive {
registerDiscover()
discoveryManager.startDiscovery()
}
}
停止
func stopDiscovery() {
if discoveryManager.discoveryActive {
removeDicover()
discoveryManager.stopDiscovery()
}
}
还有一件更奇怪的事情是,当应用程序在前台和后台之间切换时,我在控制台上看到TIC Read Status [5:0x0]: 1:57,现在我的代表被调用了。无论如何,这无济于事。
任何人都可以帮助我正确使用 googlecast sdk 手动启动和停止它。
提前致谢。
【问题讨论】:
-
为什么需要手动启动和停止?最好是让 SDK 管理发现。
-
@LeonNicholls 因为我们在特定视图中才需要此功能。我们仅使用 GoogleCast 来发现已经满足我们要求的设备。有什么好的建议吗?
-
Cast 发送者的典型用例是从应用程序开始就启用该功能,并使其在所有带有媒体的屏幕上可用。如果您的用例不同,那么您将不得不尝试解决方案。
-
@LeonNicholls 看起来 sdk 中的 cmets 并不完全可信,这让我很困惑。还是非常感谢。
标签: ios swift google-cast google-cast-sdk