You need to become the banner's delegate.
In your header file, change the @interface
line by adding <ADBannerViewDelegate>
, or add , ADBannerViewDelegate
inside the angle brackets if you already have some. In the code where you create your banner ad, add a line like this:
self.bannerAdView.delegate = self;
Or if you're using Storyboards or IB, connect the banner ad's delegate outlet to your controller.
Once that's all done, implement these methods:
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
if (!willLeave)
{
// pause your game here
}
return YES;
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
// unpause your game
}
If your entire game is landscape, I'd recommend that you set your app to only support landscape orientations. This is done in your target settings as described in this technical note. I think that this will restrict the ads to landscape, but I've only tested that on an iPad, so it may be different on the iPhone.