iOS开发-植入广告(iAd, Admob实例)
应用中植入广告是一种非常好的盈利手段。
以下介绍主流的两种方法。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
#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插屏广告
#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实例)的更多相关文章
- iOS开发基础之ivars(实例变量)与@property(属性)
Objective-C带来了一个重大改进就是Non-fragile ivar.使得i一个类可以随意增加实例变量,不必对子类重新编译.对框架开发者(如苹果)有重大意义. 最新的编译器支持@propert ...
- iOS开发——高级技术&广告功能的实现
广告功能的实现 iPhone/iPad的程序,即使是Free的版本,也可以通过广告给我们带来收入.前提是你的程序足够吸引人,有足够的下载量.这里,我将介绍一下程序中集成广告的方法.主要有两种广告iAd ...
- iOS开发之SQLite--C语言接口规范(五)——iOS开发使用SQLite实例
本篇博客就使用前面操作SQLite的知识来实现如何去插入,删除和更新数据.然后再把操作SQlite数据库常用的方法进行一个封装.把常用方法进行封装后,把Cars数据库中的其中一个表的数据进行查询,并在 ...
- 分分钟解决iOS开发中App启动广告的功能
前不久有朋友需要一个启动广告的功能,我说网上有挺多的,他说,看的不是很理想.想让我写一个,于是乎,抽空写了一个,代码通俗易懂,简单的封装了一下,各种事件用block回调的,有俩种样式的广告,一种是全屏 ...
- 【转】 学习ios(必看经典)牛人40天精通iOS开发的学习方法【2015.12.2
原文网址:http://bbs.51cto.com/thread-1099956-1.html 亲爱的学员们: 如今,各路开发者为淘一桶金也纷纷转入iOS开发的行列.你心动了吗?想要行动吗?知道如何做 ...
- 《iOS开发指南:从零基础到App Store上架(第2版)》
<iOS开发指南:从零基础到App Store上架(第2版)> 基本信息 作者: 关东升 丛书名: 图灵原创 出版社:人民邮电出版社 ISBN:9787115348029 上架时间:201 ...
- 《iOS开发指南》正式出版-源码-样章-目录,欢迎大家提出宝贵意见
智捷iOS课堂-关东升老师最新作品:<iOS开发指南-从0基础到AppStore上线>正式出版了 iOS架构设计.iOS性能优化.iOS测试驱动.iOS调试.iOS团队协作版本控制.... ...
- iOS开发系列--通讯录、蓝牙、内购、GameCenter、iCloud、Passbook系统服务开发汇总
--系统应用与系统服务 iOS开发过程中有时候难免会使用iOS内置的一些应用软件和服务,例如QQ通讯录.微信电话本会使用iOS的通讯录,一些第三方软件会在应用内发送短信等.今天将和大家一起学习如何使用 ...
- iOS开发——高级技术&广告服务
广告服务 上 面也提到做iOS开发另一收益来源就是广告,在iOS上有很多广告服务可以集成,使用比较多的就是苹果的iAd.谷歌的Admob,下面简单演示一下如何 使用iAd来集成广告.使用iAd集成广告 ...
随机推荐
- 【C++】智能指针简述(五):解决循环引用的weak_ptr
总结一下前文内容: 1.智能指针通过RAII方法来管理指针:构造对象时,完成资源初始化;析构对象时,对资源进行清理及汕尾. 2.auto_ptr,通过“转移所有权”来防止析构一块内存多次.(如何转移? ...
- MyEclipse 快捷键方法
MyEclipse企业级工作平台(My Eclipse Enterprise Workbench,简称MyEclipse)是对EclipseIDE的扩展,利用它可以在数据库和J2EE的开发.发布,以及 ...
- Spring+Spring MVC+Hibernate环境搭配
Spring+Spring MVC+Hibernate简称"SSH".Spring容器是Spring的核心,该 容器负责管理spring中的java组件.Spring的核心机制:依 ...
- Java 基础入门随笔(8) JavaSE版——静态static
面向对象(2) this:代表对象.代表哪个对象呢?当前对象. 当成员变量和局部变量重名,可以用关键字this来区分. this就是所在函数所属对象的引用.(简单说:哪个对象调用了this所在的函数, ...
- Win7访问不了WINXP共享文件
用win xp的机器可以访问,但用win 7的机器无法访问共享文件 提示:您没有权限访问.请与网络管理员联系请求访问权限 网上找了相应的资料 做了如下动作 1. 打开网上邻居→本地连接→属性里,“看是 ...
- PHP爬数据 QueryList
QueryList官方文档:https://www.querylist.cc/docs/guide/v3 因为php版本使用5.6,所以使用QueryList v3版本,php7可以使用 v4版本 v ...
- svn更新报错Please execute the 'Cleanup' command.
更新svn报错 要Clearnup一下就可以再更新了 点击svn中 clear up ok之后恢复正常
- cc.Node—场景树
对于cc.Node我分了四个模块学习: 1.场景树,2.事件响应,3.坐标系统,4.Action的使用:在此记录经验分享给大家. 场景树 1: creator是由一个一个的游戏场景组成,通过代码逻辑来 ...
- HDU - 4810 - Wall Painting (位运算 + 数学)
题意: 从给出的颜料中选出天数个,第一天选一个,第二天选二个... 例如:第二天从4个中选出两个,把这两个进行异或运算(xor)计入结果 对于每一天输出所有异或的和 $\sum_{i=1}^nC_{n ...
- CentOS \Linux 6版本系统命令及其使用详解
概述 常用的linux命令,分为文件管理.磁盘管理.用户管理.软件管理.系统管理等. 文件管理 ls命令 使用权限:所有使用者 使用方式:ls [-alrtAFR] [name...] 说明:显示指定 ...