0

I am using googlecast sdk iOS 4.0.2 version to find castable devices under same wifi network, iOS version is 10.0 or above.

I created a singleton, and register the listener to it which successfully get called when find the devices on the very first time. After that can not get called anymore.

Because I don't need to start it automatically, so here following is my code to initialize the castcontext.

    let criteria = GCKDiscoveryCriteria.init(applicationID: kGoogleCastApplicationID)
    let options = GCKCastOptions.init(discoveryCriteria: criteria)
    options.disableDiscoveryAutostart = false
    options.stopReceiverApplicationWhenEndingSession = true
    GCKCastContext.setSharedInstanceWith(

I set it to false because the following commments in the 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 */

Here's how I start and stop it.

start

    func startDiscovery() {
        if !discoveryManager.discoveryActive {
            registerDiscover()
            discoveryManager.startDiscovery()
        }
    }

stop

    func stopDiscovery() {
        if discoveryManager.discoveryActive {
            removeDicover()
            discoveryManager.stopDiscovery()
        }
    }

And one more weird thing is, on the console i see TIC Read Status [5:0x0]: 1:57 when app changing between foreground and background, and now my delegate get called. This is no helped anyway.

Anyone could help me to use the googlecast sdk correctly to start and stop it manually.

Thanks in advance.

4
  • Why do you need to start and stop it manually? The best is to let the SDK manage the discovery. Commented Apr 2, 2018 at 15:30
  • @LeonNicholls Because we don't need this feature until in the certain view. We use GoogleCast only for discovering the devices which already meet our requirement. Any good suggestion?
    – doubll liu
    Commented Apr 3, 2018 at 2:07
  • The typical use case for a Cast sender is to enabled the feature from the start of the app and make it available on all screens with media. If your use case is different then you will have to experiment on a solution. Commented Apr 4, 2018 at 19:19
  • @LeonNicholls Looks like the comments in the sdk is not fully trustable, it makes me confused. Big thanks anyway.
    – doubll liu
    Commented Apr 8, 2018 at 2:16

1 Answer 1

0

I solved this problem finally. The code above is CORRECT and the comments in the SDK is nothing wrong, but it would be better if pointing out that when start discovery again, we will not get notified the devices we found before, which means we need a container to save the devices we got and control it manually.

Not the answer you're looking for? Browse other questions tagged or ask your own question.