【问题标题】:Manage iAd banner's touch while using iAdAdditions category在使用 iAdAdditions 类别时管理 iAd 横幅的触摸
【发布时间】:2014-03-16 15:38:39
【问题描述】:

iOS 7 将 iAdAdditions 类别引入 UIViewController。 使用它管理横幅只需一行代码:

self.canDisplayBannerAds = YES;

但我想知道如何检测用户触摸 iAd 横幅。我需要在 iAd 全屏显示时暂停游戏行为(音乐、动画、计时器...)。

我尝试了以下代码:

- (void) viewWillDisappear:(BOOL)animated {
    if ([self isPresentingFullScreenAd]) {
        // view will disappear because of user action on iAd banner
    }
    else {
        // view will disappear for any other reasons
    }
}

- (void) viewWillAppear:(BOOL)animated {
    if ([self isPresentingFullScreenAd]) {
        // view will appear because full screen iAd — caused by previous user action on iAd banner — is dismissed
    }
    else {
        // view will appear for other reasons
    }
}

我做了一些测试,显示一切正常。但是不知道是不是正确的实现方式!

更新

这是我在应用程序的生产版本中使用的解决方案,一切都很好:没有显示任何问题。

【问题讨论】:

    标签: ios objective-c touch iad banner


    【解决方案1】:

    您可以在您的视图控制器中使用这些特定的委托,这里的代码直接从我的游戏中提取,当我点击横幅时,我会关闭音频/音乐。

    - (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner
                   willLeaveApplication:(BOOL)willLeave
    {
        [[CPAudioManager sharedInstance] toggleOnOffDependingOnSettings];
    
        return YES;
    }
    
    -(void)bannerViewActionDidFinish:(ADBannerView *)banner
    {
        [[CPAudioManager sharedInstance] toggleOnOffDependingOnSettings];
    }
    

    对于全屏插页式广告,代码大致相同,但你没有得到这么好的代表。

    当您调用requestInterstitialAdPresentation 并返回YES 时,您知道何时显示全屏广告,例如

    if( [self requestInterstitialAdPresentation]==YES ) {...}
    

    您应该暂停视图、关闭音乐并关闭横幅视图(可能)。

    那么,您知道用户何时关闭了ViewDidAppear 中的插页式广告

    -(void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    
        if( self.isPresentingFullScreenAd )
        {
            // we are about to stop presenting full screen ads
            // unpause view
            // enable banner ads
            // turn music back on if it was playing before
        }
        else
        {
            // we are presenting the normal view or the full screen ad
        }
    }
    

    【讨论】:

    • 我在展位 viewWillDisappearviewWillAppear 中使用了 self.isPresentingFullScreenAd 来解决这个问题。谢谢。
    • 如果这对你有用,那就太好了!我发现您不能信任 isPresentingFullScreenAd ,除非视图正在转换。例如。如果您在知道广告没有显示后随机调用它 - 它仍然是 YES。我也用示例代码向苹果报告了这一点。
    • 在 StackOverflow 上打开了与此点相关的问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多