使用 Google Cast iOS SDK 3.5.6,我有一些逻辑可以在需要时检测和恢复现有的演员会话。像这样的东西:
func connectToDevice(_ device: GCKDevice, sessionId: String?) {
var resumed = false
if let session = sessionManager.currentSession {
if session.device == device {
session.resume()
resumed = true
} else {
sessionManager.endSession()
}
}
if !resumed {
sessionManager.startSession(with: device)
}
}
GCKSession.resume()
但是,SDK v4.0.2 已弃用。我没有看到明显的替代品,并且简单地忽略现有会话不是一种选择(请参阅下面的代码作为不起作用的示例)
func connectToDevice(_ device: GCKDevice, sessionId: String?) {
if let session = sessionManager.currentSession {
sessionManager.endSession() // This doesn't help
}
DispatchQueue.main.asyncAfter(.now()+5.0) { // endSession() is asynchronous, so need to give some time
sessionManager.startSession(with: device) // This will fail in situations where 'session' isn't nil
}
}
我们希望如何使用 SDK v4.x 处理这种情况?