[objective-c]iAd 涵盖应用程序内容在 phonegap 吗?

标签: ios Objective-C
发布时间: 2016/10/4 5:07:53
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我这有我 webViewDidFinishLoad :

- (void)setupAdBanner {
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    CGRect adFrame = adView.frame;
    if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait
       || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        adView.currentContentSizeIdentifier =
        ADBannerContentSizeIdentifierPortrait;
        adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height;
    } else {
        adView.currentContentSizeIdentifier =
        ADBannerContentSizeIdentifierLandscape;
        adFrame.size.width = adView.frame.size.width;
        adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height;
    }
    adView.frame = adFrame;

    [self.view addSubview:adView];
}

这重叠在我 phonegap 应用程序中的 HTML 内容。如何调整我的 web 视图帧大小占广告横幅?

解决方法 1:

我有这个确切的问题。我博客上关于我的解决方案在这里http://hawkinbj.wordpress.com/2013/04/16/implement-iad-banner-ads-without-covering-uiwebview-in-phonegap/

您需要实现 ADBannerViewDelegateProtocolReference。在 MainViewController.h:

@interface MainViewController : CDVViewController <ADBannerViewDelegate> 
{
    ADBannerView *adView;
}
@end

剩下的步骤是在 MainViewController.m。

在 webViewDidFinishLoad:

adView.delegate = self;

添加这两种方法︰

- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{
    CGRect resizedWebView = [super webView].frame;
    resizedWebView.size.height = adView.frame.origin.y;
    [super webView].frame = resizedWebView;
    [self.view bringSubviewToFront:adView];
    adView.hidden = NO;
} 

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    CGRect resizedWebView = [super webView].frame;
    resizedWebView.size.height = self.view.frame.size.height;
    [super webView].frame = resizedWebView;
    adView.hidden = YES;
}

魔术是[self.view bringSubviewToFront:adView];

官方微信
官方QQ群
31647020