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

以下介绍主流的两种方法。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. Thread stack overrun

    ERROR 1436 (HY000): Thread stack overrun:  6448 bytes used of a 131072 byte stac k, and 128000 bytes ...

  2. .ai域名注册已经极具投资价值进入火爆期

    最近G.ai以六位数的天价被国内域名收藏家收入囊中,间接说明了.ai域名的价值不断攀升,自从2016年AlphaGo胜利以来,人工智能几乎成为人人谈资,而由于.com域名被挖掘待尽,一些聪明的人工智能 ...

  3. 动态设置缩放比例和html字体大小

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  4. [JSOI2012]玄武密码 题解(AC自动机)

    显然是AC自动机对吧 插入单词之后把文章在自动机上跑一遍,到达过的节点打上花火标记 之后检查一下每个单词有几个标记即可 可以把题目中的4个字母映射成abcd方便遍历 一定要记得把文章也映射啊! #in ...

  5. public private protected

    初学C++的朋友经常在类中看到public,protected,private以及它们在继承中表示的一些访问范围,很容易搞糊涂.今天本文就来十分分析一下C++中public.protected及pri ...

  6. CAD如何设置系统变量

    主要用到函数说明: MxDrawXCustomFunction::Mx_SetSysVar 设置系统变量.详细说明如下: 参数 说明 CString sVarName 系统变量名 Value 需要设置 ...

  7. reversed()函数和sorted()函数

    #reversed()反转排序,可对列表.元组.区间等进行排序 #练习1 a = range(10) a_list = [x for x in reversed(a)] print(a_list) # ...

  8. zip相关知识梳理(一)

    zip相关知识梳理(一) 经过对zip文件的长时间研究,对zip文件进行相关知识进行梳理,虽然网上很多牛人对其做了相关基础解析,但是对于特殊情况没有进行说明,比如超过4G的zip文件该以什么格式进行编 ...

  9. 关于js中的事件委托小案例

    需求:页面上有一个按钮,和一个空的ul,要求点击按钮,会给ul中动态添加li元素,然后,点击动态添加的元素,在控制台上输出,这是第几个元素 <ul> </ul> <but ...

  10. 【02】bootstrap起步

    起步 简要介绍 Bootstrap,以及如何下载.使用,还有基本模版和案例,等等. 下载 Bootstrap (当前版本 v3.3.5)提供以下几种方式帮你快速上手,每一种方式针对具有不同技能等级的开 ...