[英]Display Admob Banner without using Storyboard or xib
我是iOS開發的新手。 我的應用程序未使用情節提要,也無法遵循Admob iOS快速入門指南 。 我的應用程序具有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];
}
對於每個視圖,您都應確定超級視圖。 根據您的情況,這意味着您應該將GADBannerView添加到視圖中。
Google建議以委托方法進行。
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
[self.view addSubview:adView];
}
您也可以閱讀這篇文章-https://developers.google.com/mobile-ads-sdk/docs/admob/ios/ad-events
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.