我是iOS开发的新手。我的应用不使用故事板,我无法关注Admob iOS quick start guide。我的应用程序有UIViewController。这是我的代码。我添加了GADBannerView alloc
。但是,广告未在模拟器中显示。我使用的是最新的SDK 7.0.0。
- (void)viewDidLoad
{
[super viewDidLoad];
self.bannerView = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
// Replace this ad unit ID with your own ad unit ID.
self.bannerView.adUnitID = @"ca-app-pub-xxxxxxxxxxxx";
self.bannerView.rootViewController = self;
GADRequest *request = [GADRequest request];
// Requests test ads on devices you specify. Your test device ID is printed to the console when
// an ad request is made. GADBannerView automatically returns test ads when running on a
// simulator.
request.testDevices = @[
@"2077ef9a63d2b398840261c8221a0c9a" // Eric's iPod Touch
];
[self.bannerView loadRequest:request];
}
答案 0 :(得分:0)
对于每个视图,您应该确定superview。 在您的情况下,这意味着您应该将GADBannerView添加到您的视图中。
Google建议在委托方法中执行此操作。
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
[self.view addSubview:adView];
}
您也可以阅读这篇文章 - https://developers.google.com/mobile-ads-sdk/docs/admob/ios/ad-events