0

I'm trying to build a sample app using the GoogleCast sdk. I'm stuck at the first step.

For some weird reason, I'm unable to create the cast container in Obj-c.

I'm not using the pods. I downloaded the frameworks and added them to the project.

Here is the method I call in AppDelegate didFinishLaunching method:

-(void)setupChromeCastContainer {

   GCKDiscoveryCriteria *discoveryCriteria = [[GCKDiscoveryCriteria alloc]initWithApplicationID:kGCKDefaultMediaReceiverApplicationID];
    GCKCastOptions *options = [[GCKCastOptions alloc]initWithDiscoveryCriteria:discoveryCriteria];
    [GCKCastContext setSharedInstanceWithOptions:options];
    [GCKCastContext sharedInstance].useDefaultExpandedMediaControls = YES;

    UIStoryboard *st = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UINavigationController *nav = [st instantiateViewControllerWithIdentifier:@"navVc"];
    GCKUICastContainerViewController * containerVc = [[GCKCastContext sharedInstance]createCastContainerControllerForViewController:nav];
    containerVc.miniMediaControlsItemEnabled = YES;
    self.window.rootViewController = containerVc;
    [self.window makeKeyAndVisible];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self setupChromeCastContainer];
    return YES;
}

In the above method, GCKUICastContainerViewController * containerVc is returning nil. And also the nav is NOT nil, so I'm passing the valid object.

I'm unable to find why createCastContainerControllerForViewController returns nil or in which case it returns nil.

My environment is Xcode 11.3.1.

I even tried to add the cast button to the nav bar, and cast button code returns nil too.

GCKUICastButton *castButton = [[GCKUICastButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];  //castButton  returns nill
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109

1 Answers1

0

Did you check to see if nav was nil? Also is containerVc nil or is it actually uninitialized?

What you have looks similar to the sample so I would see if there is something going on in the storyboard.

I believe the main cases for when the GCKUICastContainerViewController returns nil is either when the options are not set on GCKCastContext or when a bad view controller is provided.

jtromo
  • 33
  • 6