Google AdMob Ads iOS Fundamentals
来源:互联网 发布:基金筛选软件 编辑:程序博客网 时间:2024/06/01 18:01
转自:https://developers.google.com/mobile-ads-sdk/docs/ios/fundamentals#result
Google AdMob Ads iOS Fundamentals
- Overview
- Requirements
- Incorporating the SDK
- Adding a GADBannerView
- The Result
- What's Next?
Overview
Google AdMob Ads banners use a small portion of the screen to entice users to "click through" to a richer, full-screen experience such as a website or app store page.
To display Google AdMob Ads banners in your iOS app, simply incorporate the SDK into your Xcode project and add a GADBannerView
to your UI.
For the purposes of this tutorial, the project shown will be named BannerExample. When going through the exercises, simply replace BannerExample with your project's name in the instructions.
Requirements
The Google AdMob Ads SDK for iOS requires iOS version 2.x or later (3.0 minimum for displaying ads) as well as XCode 4.2 or later.
Incorporating the SDK
The decompressed SDK consists of six Objective-C headers, a runtime library and a README.
1. Right-click on your project in Xcode, choose Add Files to "BannerExample"...
2. ...and select everything from the SDK except the README.
- AudioToolbox
- MessageUI
- SystemConfiguration
- CoreGraphics
You should now be able to rebuild your project without any errors.
Adding a GADBannerView
iOS apps are composed of UIView
objects, Objective-C instances the user sees as text areas, buttons and other controls. GADBannerView
is simply aUIView
subclass displaying small HTML5 ads that respond to user touch.
Like any UIView
, a GADBannerView
is easy to create in code.
The seven lines of code it takes to add a banner:
- Import GADBannerView.h
- Declare a GADBannerView instance in your app’s UIViewController
- Create it
- Set the ad’s unit ID – your AdMob Publisher ID
- Set the "root view controller"
- Add the view to the UI
- Load it with an ad
The best place to do all this is in your app’s UIViewController
.
// BannerExampleViewController.h// Import GADBannerView’s definition from the SDK#import "GADBannerView.h"@interface BannerExampleViewController : UIViewController { // Declare one as an instance variable GADBannerView *bannerView_;}@end
The following performs banner setup in the view controller’s viewDidLoad
initialization hook.
// BannerExampleViewController.m#import "BannerExampleViewController.h"@implementation BannerExampleViewController- (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 = 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.view addSubview:bannerView_]; // Initiate a generic request to load it with an ad. [bannerView_ loadRequest:[GADRequest request]];}- (void)viewDidUnload { [bannerView_ release];}- (void)dealloc { [super dealloc];}@end
Warning: Make sure you're in test mode during development to avoid being disabled for clicking your own ads. See the Best Practices guide for more details on enabling test ads.
You can download an example project containing this code here.
The Result
The outcome of either technique should be a banner at the bottom of your app:
Note: The very first time AdMob sees your publisher ID it may take up to two minutes to receive an ad. This initial two minute lag will recur every time the app goes unused for 24 hours. Refer to the Best Practices section if you would like to request test ads to make sure that your request code is working correctly.
Warning: All new iPad and iPhone apps created after October 14, 2011 will require an AdMob SDK that was released on or after March 15, 2011. This corresponds to version 4.0.2+ for iOS. If you downloaded the library from our official download site, then you're already set. Otherwise you may have an old version of the AdMob SDK that was released prior to March 15, 2011, and your new app will not receive any ad impressions until you update your SDK.
What's Next?
The Intermediate guide explains banner configuration in more detail.
- Google AdMob Ads iOS Fundamentals
- Google AdMob Ads iOS Fundamentals
- Google AdMob Ads Android Fundamentals
- cocos2d 使用 cocoapods 安装 google admob ads sdk
- Google张伟彬:详解Admob iOS应用推广
- Google AdMob 广告 iOS 初级指南
- Google AdMob 广告 iOS 初级指南
- 测试Android Studio自动生成Demo(ADmob ADs Activity,Google Maps)
- google ads
- ios应用中利用Google AdMob投放广告
- 2012年3月最新版的ADT 17.0和Google AdMob Ads Sdk Android-4.3.1添加广告的方法
- Google Android admob
- Google AdMob 广告使用
- google ads (2)
- 这样去掉google-ads
- Google Mobile Ads SDK
- iOS 使用admob广告
- Google Admob广告Android攻略
- 硬盘内部硬件结构和工作原理详解
- 做个会说话会办事的人!
- TWITTER背后的开源技术
- gamecenter peer - to -peer
- Android利用ViewFlipper实现屏幕切换动画效果
- Google AdMob Ads iOS Fundamentals
- erdas9.2 破解方法
- c语言中静态变量和静态函数
- Android各种访问权限Permission详解
- wince简单绘图
- 学习资源网址大全
- hdu 3401 Trade 单调队列优化dp
- memcached 深度解剖
- linux各文件夹的作用