当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Handling iAd banner clicked in my game

问题描述:

I successfully added an iAd banner to my game (which plays in landscape mode), however I'm lost as to how to handle the ad being pushed. When the banner ad is pushed the game continues in the background and the player dies. Is there code to pause the game when the banner ad is clicked and resume when the ad goes away? Also when the banner ad is clicked, the ad shows up in portrait mode. Can I keep the ad in landscape mode so it is in sync with my landscape game? I'm a newbie please bear with me thanks!

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: