iAd涵盖了phonegap中的应用内容?

时间:2013-02-22 03:21:47

标签: ios objective-c cordova iad

我在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内容重叠。如何调整我的网页框架尺寸以考虑广告横幅?

1 个答案:

答案 0 :(得分: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];