With the Google Cast iOS SDK 3.5.6 I had some logic in place to detect and resume a an existing cast session when needed. Something like this:
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()
is deprecated with SDK v4.0.2 however. I am seeing no obvious replacement, and simply ignoring existing sessions is not an option (see below code as an example of what does not work)
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
}
}
How are we expected to handle this situation with SDK v4.x?