iOS项目加入iAD,Admob的简单代码
来源:互联网 发布:飞耀速录软件 编辑:程序博客网 时间:2024/05/21 14:59
项目需要加广告,所以看了一下相关代码,很简单.
1.iAD 需要加入iad.framework
//.h#import <UIKit/UIKit.h>#import <iAd/iAd.h>@interface ViewController : UIViewController<ADBannerViewDelegate>@end
//.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");}
2.admob
需要加入第三方文件,以及如下framework
#define ADID @"xxxxxxx"//设置一个自己的全局id
//.H#import <UIKit/UIKit.h>#import "GADBannerView.h"@interface AdmobDefaultViewController : UIViewController{ GADBannerView *ADView;}@end
- (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]];}
3.ADMOB插屏广告
#import <UIKit/UIKit.h>#import "GADInterstitial.h"#import "GADInterstitialDelegate.h"@interface InterAdmobViewController : UIViewController<GADInterstitialDelegate>@property(nonatomic, retain) GADInterstitial *interstitial;@end
- (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]; return request;}- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial { [interstitial presentFromRootViewController:self];}
参考链接: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程序
- 纯粹透明背景的QGraphicsView
- Flip Game
- 汇编字符串处理指令stosb、lodsb、movsw、scasb、rep
- js中的null和undefined的区别
- 加密术
- iOS项目加入iAD,Admob的简单代码
- c语言基础之动态内存分配
- (beginer) 旋转卡壳 UVA 12307 - Smallest Enclosing Rectangle
- Vim进阶简明手册(2)
- WINDOWS下PHP+Apache环境的搭建
- android权限代码分析(六)
- 求二叉树的先序遍历
- 指针函数与函数指针的区别
- 数据结构上机测试4.1:二叉树的遍历与应用1