我正在使用最新的 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 已经在常量文件中定义,所以一切都应该正常工作,但我想我错过了一些东西。有什么帮助吗?