iOS如何植入admob广告

转自:http://blog.sina.com.cn/s/blog_6fe6da8301019cuv.html

 

具体做法可参见: https://developers.google.com/mobile-ads-sdk/docs/#incorporating
之后就要在项目中加入code. 登陆admob后可下载到例子程序:
1. 在.h中    声明变量  GADBannerView   *adBanner_;
2. 导入框架MessageUK.framework, AudioToolbox.framework, systemConfiguration.framework
3. 在viewDidAppear(或者其他地方)加入如下代码:

CGPoint origin = CGPointMake(0.0, 0.0);

 // Use predefined GADAdSize constants to define the GADBannerView.

 self.adBanner = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner

                                                    origin:origin] autorelease];

// Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID

 // before compiling.

self.adBanner.adUnitID = kSampleAdUnitID;

self.adBanner.delegate = self;

[self.adBanner setRootViewController:self];

[self.view addSubview:self.adBanner];

[self.adBanner loadRequest: [GADRequest request]];

4. 如果有必要实现起delegate方法

 

#pragma mark GADBannerViewDelegate impl

// We've received an ad successfully.

- (void)adViewDidReceiveAd:(GADBannerView *)adView {

    NSLog(@"Received ad successfully");

}

- (void)adView:(GADBannerView *)view

didFailToReceiveAdWithError:(GADRequestError *)error {

    NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]);

}

5. 在build Setting中,将 Other Linker Flags, add -ObjC to both Debug and Release.

大功告成,运行程序就可以在屏幕上方看到admob广告了,这里的kSampleAdUnitID是你注册在admob注册程序后的Publisher ID

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值