0

我正在使用最新的 Xcode (4.4.1) 并为 iOS 5.1 开发。我正在使用 Apple 提供的底部标签栏界面。其中一个选项卡使用了一个 UIWebView,它利用了全屏空间。当我尝试添加 AdMob 提供的标准横幅时,它根本不添加横幅。我跟着:https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals。下面附上代码

关于.h

#import <UIKit/UIKit.h>
#import "GADBannerView.h"

@interface About : UIViewController <UIWebViewDelegate> {
    IBOutlet UIWebView *webView;

    // Declare one as an instance variable
    GADBannerView *bannerView_;
}

@property (nonatomic, retain) UIWebView *webView;

@end

关于.m

#import "About.h"
#import "GADBannerView.h"
#import "GADRequest.h"
#import "constants.h"

@implementation About

@synthesize webView;
//@synthesize bannerView = bannerView_;

+ (void)initialize {
    // Set user agent (the only problem is that we can't modify the User-Agent later in the program)
    NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:UserAgent, @"UserAgent", nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *fullURL = ([IsBeta isEqualToString: @"true"]) ? @"http://beta.wouldyouratherapp.com/questions/index/0/1" : @"http://wouldyouratherapp.com/questions/index/0/1";
    NSURL *url = [NSURL URLWithString:fullURL]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj];

    // Create a view of the standard size at the bottom of the screen.
    // Available AdSize constants are explained in GADAdSize.h.
    bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];

    // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
    bannerView_.adUnitID = MyAdUnitID;

    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    bannerView_.rootViewController = self;
    [self.view addSubview:bannerView_];

    // Initiate a generic request to load it with an ad.
    [bannerView_ loadRequest:[GADRequest request]];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

@end

是的,我已经添加了所有框架,并且 MyAdUnitID 已经在常量文件中定义,所以一切都应该正常工作,但我想我错过了一些东西。有什么帮助吗?

4

1 回答 1

1

如果要添加bannerView_,则必须webView相应降低高度,以便为bannerView_. 由于广告的来源看起来像是在 (0,0),因此您可能希望在adView:DidReceiveAd: 回调中使用与此类似的内容:

webView.frame = CGRectMake (0, bannerView_.frame.size.height, webView.frame.size.width, webView.frame.size.height - bannerView_.frame.size.height);
于 2012-08-13T14:34:18.487 回答