iOS项目加入iAD,Admob的简单代码
来源:互联网 发布:2017年阳春市网络问政 编辑:程序博客网 时间:2024/05/16 07:38
项目需要加广告,所以看了一下相关代码,很简单.
1.iAD 需要加入iad.framework
- <span style="font-size:18px;">//.h
- #import <UIKit/UIKit.h>
- #import <iAd/iAd.h>
- @interface ViewController : UIViewController<ADBannerViewDelegate>
- @end</span>
- <span style="font-size:18px;">//.m
- #import "ViewController.h"
- @interface ViewController ()
- @property (nonatomic,strong)ADBannerView *adView;
- @end
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.adView = [[ADBannerView alloc]initWithFrame:CGRectMake(0, 80, 320, 100)];
- self.adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
- self.adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
- self.adView.delegate = self;
- [self.view addSubview:self.adView];
- }
- - (void)bannerViewWillLoadAd:(ADBannerView *)banner{
- NSLog(@"bannerViewWillLoadAd");
- }
- - (void)bannerViewDidLoadAd:(ADBannerView *)banner
- {
- NSLog(@"bannerViewDidLoadAd");
- }
- - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
- {
- NSLog(@"didFailToReceiveAdWithError");
- }
- </span>
2.admob
需要加入第三方文件,以及如下framework
- <span style="font-size:18px;">#define ADID @"xxxxxxx"
- //设置一个自己的全局id</span>
- <span style="font-size:18px;">//.H
- #import <UIKit/UIKit.h>
- #import "GADBannerView.h"
- @interface AdmobDefaultViewController : UIViewController
- {
- GADBannerView *ADView;
- }
- @end</span>
- <span style="font-size:18px;">
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- // Create a view of the standard size at the bottom of the screen.
- ADView = [[GADBannerView alloc]
- initWithFrame:CGRectMake(0.0,self.view.frame.size.height - GAD_SIZE_320x50.height,GAD_SIZE_320x50.width,GAD_SIZE_320x50.height)];
- ADView.adUnitID = ADID;//调用id
- ADView.rootViewController = self;
- ADView.backgroundColor = [UIColor yellowColor];
- [self.view addSubview:ADView];
- [ADView loadRequest:[GADRequest request]];
- }</span>
3.ADMOB插屏广告
- <span style="font-size:18px;">
- #import <UIKit/UIKit.h>
- #import "GADInterstitial.h"
- #import "GADInterstitialDelegate.h"
- @interface InterAdmobViewController : UIViewController<GADInterstitialDelegate>
- @property(nonatomic, retain) GADInterstitial *interstitial;
- @end</span>
- <span style="font-size:18px;">
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.interstitial = [[GADInterstitial alloc] init];
- self.interstitial.delegate = self;
- self.interstitial.adUnitID = ADID;
- [self.interstitial loadRequest: [self createRequest]];
- }
- - (GADRequest *)createRequest {
- GADRequest *request = [GADRequest request];
- // Make the request for a test ad. Put in an identifier for the simulator as
- // well as any devices you want to receive test ads.
- request.testDevices =
- [NSArray arrayWithObjects:
- // TODO: Add your device/simulator test identifiers here. They are
- // printed to the console when the app is launched.
- nil nil];
- return request;
- }
- - (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
- [interstitial presentFromRootViewController:self];
- }
- </span>
参考链接:https://developers.google.com/mobile-ads-sdk/docs/admob/advanced?hl=zh-CN#iOS
源码:http://download.csdn.net/detail/woshiwls/6931237
0 0
- iOS项目加入iAD,Admob的简单代码
- iOS项目加入iAD,Admob的简单代码
- iOS项目加入iAD,Admob的简单代码
- 分享AdMob + iAd部署代码
- iOS开发-植入广告(iAd, Admob实例)
- iOS开发-植入广告(iAd, Admob实例)
- iOS开发-植入广告(iAd, Admob实例)
- iAd和admob混用
- 将AdMob加入iOS应用中
- ios iAd
- cocos2dx2.2.5在iOS下加入Google AdMob可能会遇到的问题
- demo for Swift with Admob/iAd/Interstitial
- ios 项目添加AdMob 错误记录
- admob 广告代码参考 iOS 奖励视频
- admob 广告代码参考 iOS banner广告
- iad-simulator项目设计介绍(一个基于Python的IAD终端模拟器)
- iOS:集成iAd广告
- 分步使用iAd的工作台,推广你的iOS程序
- 照片美化
- Redis在PHP中的简单应用
- Linux下修改Mysql数据库存放路径
- java内存管理-内存回收
- 对计算机等相关技术思考
- iOS项目加入iAD,Admob的简单代码
- 判断学生成绩等级
- 我是一个线程,我的短暂一生
- PAT 1001. A+B Format C语言
- TCP/IP 相关知识点与面试题集
- IOS 最全动画教程(基础)
- js常用API汇总
- 四模型代码管理
- java面试题