我想在我的应用中加入 AdMob 横幅!我让它在 UIViewcontrollers 中工作,但不是在我的 UIView 中......横幅出现了,但是当你点击它时,什么也没有发生!如果您单击 UIViewcontrollers 中的横幅,它会起作用!
UIViewcontrollers 中的代码(有效!)
- (void)viewDidLoad
{
[super viewDidLoad];
bannerView_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height - GAD_SIZE_320x50.height-49, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
GADRequest *r = [[GADRequest alloc] init];
r.testing = YES;
[bannerView_ loadRequest:r];
// Do any additional setup after loading the view, typically from a nib.
}
UiView 中的代码:(不起作用)
- (void)drawRect:(CGRect)rect
{
// Create a view of the standard size at the bottom of the screen.
bannerView_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.frame.size.height - GAD_SIZE_320x50.height, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
// 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 addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
// Drawing code
}
行bannerView_.rootViewController = self; 给我一个警告,但没有它就不行!警告说“不兼容的指针类型从 'blandad *const_strong' 分配给 'UIViezController *'
UIView 的 .m 和 .h 文件的名称中的 blandad!
你觉得哪里不对?
/一个菜鸟