2013-02-08 146 views
2

這是一個Phonegap應用程序。我完全迷失在這裏,請幫忙。 我跟着this tutorial到了t。無廣告時隱藏iAd橫幅

這裏是我的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]; 
} 

回答

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; 
} 
+0

太謝謝你了!這工作=)除了在廣告加載橫幅之前還在那裏。有任何想法嗎? – user2052886

+0

是的,只需添加'adView.hidden = YES;'到您的原始方法,它會隱藏它,直到一個廣告加載 –

+0

謝謝你現在完美=)你有什麼技巧來讓廣告停止重疊我的.html內容? – user2052886