I am new in iOS development. My app do not using storyboard and I cannot follow the Admob iOS quick start guide . My app has UIViewController. Here is my code. I added GADBannerView alloc
. However, the ads is not showing in simulator. I am using the latest 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];
}
For each view you should determine superview. In your situation this means that you should add GADBannerView to your view.
Google recommends to do it in delegate method.
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
[self.view addSubview:adView];
}
Also you can read this article - https://developers.google.com/mobile-ads-sdk/docs/admob/ios/ad-events
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.