Search code examples
iossprite-kitadmobinterstitial

No UIViewController supplied to the ad. Cannot continue


I have a sprite-kit game, and the first ad loads on gameOver, but the following gameOver's after that give the following error :

<Google> No UIViewController supplied to the ad. Cannot continue.

This is how my code looks:

initWithSize:

-(id)initWithSize:(CGSize)size { 
    if (...]) {
        ...

        self.interstitial = [[GADInterstitial alloc] init];
        self.interstitial.adUnitID = @"ca-app-pub-9147160832662960/2548046734";
        GADRequest *request = [GADRequest request];
        // Requests test ads on simulators.
        [self.interstitial loadRequest:request];
        ...
    }
    return self;
}

gameOver:

-(void)gameOver
{
    self.isGameOver = YES;
    ...

    if ([self.interstitial isReady]) {
        self.interstitial.delegate = self;
        [self.interstitial presentFromRootViewController:_viewController];
    }
   ...
}

Solution

  • scene.viewController = self.viewController;
    

    This is what was required to be added to the initWithSize in my GameScene. Works perfectly now