我想在我的 ios 应用程序中添加 admob。
我已按照该教程进行操作:
https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals?hl=en#ios
但即使使用示例项目或使用该代码在我的 ios 项目中添加源代码,我也有一个错误:
*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[GADBannerView private]:无法识别的选择器发送到实例 0x1727d0”
使用该源代码:
视图控制器.h
#import <UIKit/UIKit.h>
#import "GADBannerView.h"
@interface ViewController : UIViewController{
GADBannerView *bannerView_;
}
@end
和
视图控制器.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Create a view of the standard size at the bottom of the screen.
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.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 = @"MYID";
// 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];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end