应用中植入广告是一种非常好的盈利手段。

以下介绍主流的两种方法。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];
}


iOS开发-植入广告(iAd, Admob实例)的更多相关文章

  1. iOS开发基础之ivars(实例变量)与@property(属性)

    Objective-C带来了一个重大改进就是Non-fragile ivar.使得i一个类可以随意增加实例变量,不必对子类重新编译.对框架开发者(如苹果)有重大意义. 最新的编译器支持@propert ...

  2. iOS开发——高级技术&广告功能的实现

    广告功能的实现 iPhone/iPad的程序,即使是Free的版本,也可以通过广告给我们带来收入.前提是你的程序足够吸引人,有足够的下载量.这里,我将介绍一下程序中集成广告的方法.主要有两种广告iAd ...

  3. iOS开发之SQLite--C语言接口规范(五)——iOS开发使用SQLite实例

    本篇博客就使用前面操作SQLite的知识来实现如何去插入,删除和更新数据.然后再把操作SQlite数据库常用的方法进行一个封装.把常用方法进行封装后,把Cars数据库中的其中一个表的数据进行查询,并在 ...

  4. 分分钟解决iOS开发中App启动广告的功能

    前不久有朋友需要一个启动广告的功能,我说网上有挺多的,他说,看的不是很理想.想让我写一个,于是乎,抽空写了一个,代码通俗易懂,简单的封装了一下,各种事件用block回调的,有俩种样式的广告,一种是全屏 ...

  5. 【转】 学习ios(必看经典)牛人40天精通iOS开发的学习方法【2015.12.2

    原文网址:http://bbs.51cto.com/thread-1099956-1.html 亲爱的学员们: 如今,各路开发者为淘一桶金也纷纷转入iOS开发的行列.你心动了吗?想要行动吗?知道如何做 ...

  6. 《iOS开发指南:从零基础到App Store上架(第2版)》

    <iOS开发指南:从零基础到App Store上架(第2版)> 基本信息 作者: 关东升 丛书名: 图灵原创 出版社:人民邮电出版社 ISBN:9787115348029 上架时间:201 ...

  7. 《iOS开发指南》正式出版-源码-样章-目录,欢迎大家提出宝贵意见

    智捷iOS课堂-关东升老师最新作品:<iOS开发指南-从0基础到AppStore上线>正式出版了 iOS架构设计.iOS性能优化.iOS测试驱动.iOS调试.iOS团队协作版本控制.... ...

  8. iOS开发系列--通讯录、蓝牙、内购、GameCenter、iCloud、Passbook系统服务开发汇总

    --系统应用与系统服务 iOS开发过程中有时候难免会使用iOS内置的一些应用软件和服务,例如QQ通讯录.微信电话本会使用iOS的通讯录,一些第三方软件会在应用内发送短信等.今天将和大家一起学习如何使用 ...

  9. iOS开发——高级技术&广告服务

    广告服务 上 面也提到做iOS开发另一收益来源就是广告,在iOS上有很多广告服务可以集成,使用比较多的就是苹果的iAd.谷歌的Admob,下面简单演示一下如何 使用iAd来集成广告.使用iAd集成广告 ...

随机推荐

  1. PAT甲级考前整理(2019年3月备考)之一

       转载请注明出处:https://www.cnblogs.com/jlyg/p/7525244.html 终于在考前,刷完PAT甲级131道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种 ...

  2. JavaScript设计模式 (1) 原型模式

    原型模式(Prototype):用原型实例指向创建类对象,使用于创建新对象的类共享原型对象的属性以及方法. //图片轮播类 var LoopImages = function (imgArr, con ...

  3. jsp学习笔记 - 内置对象 config

    1.将页面保存在 WEB-INF文件夹下是最安全的,一般不可见 可以通过映射路径来进行访问 2.通过config对象可以取得初始化的配置参数 String dbDriver = config.getI ...

  4. Python 开发初识

    从今天开始记录自己的python开发之路,用博客记录自己的学习经历,以及学习小结,小的项目模块,努力充实,做最好的自己!!!

  5. mysqlbinlog flashback 使用最佳实践

    mysqlbinlog限制 该软件利用binlog中记录了操作前的数据镜像和操作后的数据镜像.有如下限制 1)binlog_format=row 2)必须打开binlog 3)只支持insert.up ...

  6. UI布局只关乎三件事情:尺寸、位置、组织

    UI布局只关乎三件事情:尺寸.位置.组织. 组织分为两类: 单元组织: 集合组织: 混合组织.

  7. RabbitMQ系列(三)--Java API

    基于java使用RabbitMQ 框架:SpringBoot1.5.14.RELEASE maven依赖: <dependency> <groupId>com.rabbitmq ...

  8. EXP-00083: 调用 EXFSYS.DBMS_EXPFIL_DEPASEXP.schema_info_exp 时出现前一问题

    select owner,object_name,object_type,status from dba_objects where object_name = 'LT_EXPORT_PKG'; 如果 ...

  9. linux ifstat-统计网络接口流量状态

    推荐:更多linux 性能监测与优化 关注:linux命令大全 ifstat命令就像iostat/vmstat描述其它的系统状况一样,是一个统计网络接口活动状态的工具.ifstat工具系统中并不默认安 ...

  10. redis学习-简介

    1. Redis 简介 1.1 Redis是什么 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统.Red ...