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集成广告 ...
随机推荐
- SQLiteOpenHelper学习
0.视频:http://www.imooc.com/video/3384 1.SQLiteOpenHelper笔记: 2.SQLiteOpenHelper.java代码: import android ...
- ecpilse将Web项目转变为Java工程
转需: 用Eclipse开发项目的时候,把一个Web项目导入到Eclipse里会变成了一个Java工程,将无法在Tomcat中进行部署运行. 以下为将Java工程转变为Web项目的方法: 1.找到项目 ...
- Python-Day07-图形用户界面和游戏开发
Python-100Day-学习打卡Author: Seven_0507Date: 2019-05-22123 文章目录Python图形用户界面和游戏开发1. tkinter模块2. Pygame进行 ...
- 从输入URL到网页呈现的过程
1.域名解析当我们在浏览器中输入一个URL,例如”www.google.com”时,这个地址并不是谷歌网站真正意义上的地址.互联网上每一台计算机的唯一标识是它的IP地址,因此我们输入的网址首先需要先解 ...
- 05C语言数组
C语言数组 一维数组 类型符 数组名[常量表达式] #include <stdio.h> int main(){ ] = {,,,}; int a; ;a<;a++){ printf ...
- Linux常用命令——帮助命令
1.帮助命令:man man 命令 获取指定命令的帮助 [dmtsai@study ~]$ man date DATE (1) User Commands DATE(1) #注意这个(1),代表的是m ...
- SAS,SATA普及文档
目前所能见到的硬盘接口类型主要有IDE.SATA.SCSI.SAS.FC等等. IDE是俗称的并口,SATA是俗称的串口,这两种硬盘是个人电脑和低端服务器常见的硬盘.SCSI是"小型计算机系 ...
- The method buildSessionFactory() from the type Configuration is deprecated.SessionFactory的变化
在创建Configuration对象之后:Configuration cfg = new Configuration().configure(); 要通过Configuration创建SessionF ...
- Vue.js 计算属性(computed)
Vue.js 计算属性(computed) 如果在模板中使用一些复杂的表达式,会让模板显得过于繁重,且后期难以维护.对此,vue.js 提供了计算属性(computed),你可以把这些复杂的表达式写到 ...
- console.log格式化及console对象
一.console.log格式化打印 console.log格式化这一用法一般都在个人博客或其他官网上有,当F12查看网页元素时,在控制台(console)那里偶尔会发现一些个性化的输出,感觉很奇特很 ...