Search code examples
objective-cswiftiad

iAd in Sprite Kit Pauses the scene


I have a problem implementing iAd banner, everything works fine until the banner is tapped, the banner navigation works fine.

When i close the add the Sprite kit Scene is like frozen, update method is working because i can see the NSLog's there....but everything is just as it was before tapping the add, even if i tap , nothing works or at least its not being showed...

So my question is How to "resume" the game after closing the add, iAd uses some kind of self.view.paused = YES; ?

I've been reading a lot, even at apple documentation but i can't find the way they "pause" my game, here i show you the implementation of iAD which is so poor i guess..

@implementation GoViewController

- (void)viewDidLoad
{
    [super viewDidLoad];


    skView = (SKView *)self.view;
    //skView.showsFPS = YES;
    //skView.showsNodeCount = YES;

    // Create and configure the scene.
    scene = [GoMyScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    // Present the scene.
    NSLog(@"%@",skView);
    self.canDisplayBannerAds = YES;



    [skView presentScene:scene];
}

- (BOOL)shouldAutorotate
{
    return YES;
}
-(void)viewWillLayoutSubviews{

}
- (NSUInteger)supportedInterfaceOrientations
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}
- (BOOL)prefersStatusBarHidden {
    return YES;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];
    NSLog(@"ADD ON");

}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [banner setAlpha:0];
   // [UIView commitAnimations];
    NSLog(@"ADD OFFFFFFFF");

}



-(void)bannerViewActionDidFinish:(ADBannerView *)banner{

    NSLog(@"banner finished");
    //[self bannerViewActionShouldBegin:banner willLeaveApplication:YES];
    //[UIView setAnimationBeginsFromCurrentState:YES];


}
-(void)bannerViewWillLoadAd:(ADBannerView *)banner{
    NSLog(@"banner starting to show");

}

Solution

  • There is usually a problem when using self.canDisplayBannerAds with spritekit. I have tried endlessly to get it to work, but to no avail. Instead, I use this code:

    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.delegate = self;
    [adView setFrame:CGRectMake(0, 0, 1024, 768)]; // set to your screen dimensions
    [adView setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:adView];
    

    First initialize a ADBannerView *adView variable in your Viewcontroller's interface file, then you can use the above code in your ViewDidLoad method.

    It works perfectly for me, and doesn't have any issues with pausing or unresponsive screen after clicking the ad.