iOS开发-植入广告(iAd, Admob实例)
2024-08-31 00:34:36
应用中植入广告是一种非常好的盈利手段。
以下介绍主流的两种方法。iAd, Admob
先mark一个非常具体的pdf。 http://pan.baidu.com/share/link?shareid=1656439633&uk=1394536315&fid=406566606116897
一。iAd
1.须要增加iAd.framework
2. .h文件增加例如以下代码
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
@interface ViewController : UIViewController<ADBannerViewDelegate>
3. .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, 64, 320, 50)];
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");
}
效果图:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGl0d2h5bHo=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
二。admob
1.须要增加第三方文件,以及例如以下framework
2.
#define ADID @"xxxxxxx"
//设置一个自己的全局id
3. .h文件增加例如以下代码
#import <UIKit/UIKit.h>
#import "GADBannerView.h"
@interface AdmobDefaultViewController : UIViewController
{
GADBannerView *ADView;
}
3. .m文件增加例如以下代码
- (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插屏广告
.h文件代码
#import <UIKit/UIKit.h>
#import "GADInterstitial.h"
#import "GADInterstitialDelegate.h" @interface InterAdmobViewController : UIViewController<GADInterstitialDelegate> @property(nonatomic, retain) GADInterstitial *interstitial; @end
.m文件代码
- (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];
}
最新文章
- [原创]MYSQL的简单入门
- javaweb优化
- [SQL]复制数据库某一个表到另一个数据库中
- NanoProfiler - 适合生产环境的性能监控类库 之 基本功能篇
- WeisEditor 3.2.1B 使用说明 [源码下载]
- [NOIP2011] 普及组
- Python打包程序
- mysql 分页存储过程 一次返回两个记录集(行的条数,以及行记录),DataReader的Read方法和NextResult方法
- JAVA_SE复习(OOP1)
- IoSkipCurrentIrpStackLocation .(转)
- lock语句的递归问题
- Ngui _CD技能特效
- angular实例
- openstack私有云布署实践【14.1 登录页dashboard-controller(科兴环境)】
- 关于ZendStudio 10.5的破解 包括mac
- 面向对象_03【关键字:final使用】
- Luogu3527:[POI2011]MET-Meteors
- openflow 和 sdn (软件定义网络) 原理和教程
- Linux用户登录日志查询
- Maven为不同环境配置打包
热门文章
- Redis系列(二)--分布式锁、分布式ID简单实现及思路
- SpringMVC接收多参数的处理方法
- TestNG套件测试(一)
- VS C#报错CS1056意外的字符";(Unexpected Character";)
- 信息的表示和处理 及 CS:APP 15213 datalab
- pageContext对象的使用及常用方法
- Linux下常用的操作
- Tampermonkey脚本安装问题及自用脚本推荐
- 1.ARM嵌入式体系结构与接口技术(Cortex-A8版)
- [bzoj2141][排队] (分块大法好)