2

这是一个Phonegap 应用程序。我在这里完全迷路了,请帮忙。我按照本教程进行了操作。

这是我的 MainViewController.m:

- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];


    if([UIApplication sharedApplication].statusBarOrientation ==
       UIInterfaceOrientationPortrait ||
       [UIApplication sharedApplication].statusBarOrientation ==
       UIInterfaceOrientationPortraitUpsideDown) {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    }
    else {
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }


    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    CGRect adFrame = adView.frame;
    adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height;
    adView.frame = adFrame;
    [self.view addSubview:adView];

    // Black base color for background matches the native apps
    theWebView.backgroundColor = [UIColor blackColor];

    return [super webViewDidFinishLoad:theWebView];
}
4

1 回答 1

8

快速回答:您需要做的是符合 ADBannerViewDelegate 协议,并在收不到广告时隐藏广告。

分步版本:

在您列出的该方法中,您还需要包括adView.delegate = self.

在 MainViewController.h 中,它说@interface MainViewController : UIViewController,您想在<ADBannerViewDelegate>之后添加,如下所示:

@interface MainViewController : UIViewController <ADBannerViewDelegate>. 如果<>里面已经有东西了,加个逗号,加上ADBannerViewDelegate。

回到 MainViewController.m,添加这些方法:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
   adView.hidden = NO;
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
   adView.hidden = YES;
}
于 2013-02-08T01:36:05.560 回答