I find that tapping on iAds can freeze the screen on any Sprite Kit game. It's not just my specific project, since the stock Sprite Kit example project also freezes with iAd. This does not happen in the simulator though! I cannot decide whether if it's because the simulator runs iOS 8 and my actual testing device is on 7.1, or because of the fact that the simulator is just a simulator so it does things differently.

So if you tap on the iAd then click on the link in the iAd to go to safari (or manually switch over to any app at this point), then switch back to the Sprite Kit app, the app is frozen. The iAd banner is still live, and it loads ads just how it's supposed to. But the rest of the app is frozen. Or to be specific, It still receives touches and stuff (I can see from NSLogs) but the rendering of the nodes is frozen. If you open up iAd again by tapping on it, and close the iAd, then the app resumes somehow and it works again just fine.

If you're curious, here are the ONLY modifications that I did to the stock Sprite Kit example project:

// in GameViewController.h
#import <iAd/iAd.h>

@interface GameViewController : UIViewController <ADBannerViewDelegate>
@end


// in GameViewController.m
@interface GameViewController() {
    ADBannerView*       iAdBanner;
    NSLayoutConstraint* centerAd;
}
@end

@implementation GameViewController
- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure iAd
    iAdBanner           = [[ADBannerView alloc] initWithFrame:CGRectZero];
    iAdBanner.alpha     = 0.0;
    iAdBanner.delegate  = self;
    centerAd            = [NSLayoutConstraint constraintWithItem:iAdBanner
                                                   attribute:NSLayoutAttributeCenterX
                                                   relatedBy:NSLayoutRelationEqual
                                                      toItem:self.view
                                                   attribute:NSLayoutAttributeCenterX
                                                  multiplier:1.0
                                                    constant:0.0];
    [self.view addSubview:iAdBanner];
    [self.view addConstraint:centerAd];

    // The rest of viewDidLoad is the stock code. I'm not pasting that in...
}

// iAd delegate methods

-(void) bannerViewDidLoadAd:(ADBannerView *)banner {
    // fade in iAd banner
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [banner setAlpha:1.0];
    [UIView commitAnimations];
}

-(void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"iAd error: %@", error.localizedDescription);
    banner.alpha = 0.0;
}

Plus I set the deployment target to 7.1 (and obviously include the iAd framework in the project).

As you can see, I'm not doing anything to the app that could cause this crash. I simply add the iAd banner and that's it. So the problem is not in my code. This must be a bug in Apple's frameworks.

Does anyone know a workaround? I have found several topics on this on the internet, but nobody could suggest a working solution.

Related posts

Recent Viewed