1

I have set up a channel to receive messages from the receiver app:

import Foundation
import GoogleCast

class GcastChannel: GCKCastChannel {

    var gcastDelegate: GcastDelegate?

    override func didReceiveTextMessage(_ message: String) {
        if let jsonData = message.data(using: .utf8) {
            do {
                let gcastEvent = try JSONDecoder().decode( GcastEvent.self, from: jsonData)
                gcastDelegate?.didReceiveGcastEvent(event: gcastEvent)
            } catch {
                print("message decode error: \(error)")
            }
        }
    }
}

And set up the session manager and listener in the main view controller:

func sessionManager(_ sessionManager: GCKSessionManager, didStart session: GCKCastSession) {
    castSession = session
    castSession?.add(gcastChannel)
    gcastChannel.gcastDelegate = self
}

It works perfectly when the app is in the foreground, but when the app is in the background, it does not respond to events anymore. In addition, when the app is put in the foreground again, the app is still unresponsive to the events being sent.

How do I get the app to respond to events while the app is in the background?

1 Answers1

0

Based from this link, no new media can be pushed from the app to the chromecast while the app is in the background.

With the version 2.0 of the iOS Sender API, the GCKCastSocket is closed upon receiving a UIApplicationDidEnterBackgroundNotification and this is not something that can be configured.

You may also refer with this post: How to keep Chrome Cast running in background iOS?.

abielita
  • 13,147
  • 2
  • 17
  • 59