- 浏览: 200189 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
feihumingyue:
nice 很好啊
JSF中如何使用FacesContext类 -
wgcniler:
请问如果传到存储过程的参数是一个嵌套表的话该怎么写?自定义的o ...
spring中调用存储过程 -
wgcniler:
请问如果传到存储过程的参数是ARRAY,但ARRAY的元素不是 ...
spring中调用存储过程 -
bengan:
谢谢楼上的提示
关于出现僵尸信号SIGBAT或者EXC_BAD_ACCESS的解决方案 -
gypgyp:
用xcode的菜单:product/profile,弹出窗口中 ...
关于出现僵尸信号SIGBAT或者EXC_BAD_ACCESS的解决方案
本段教程和代码例子由 CocoaChina 会员“巫山冰”分享,可以自动识别 iPhone 所在地区,如果是美、日、英、法、德等支持 iAd 广告的国家,显示 iAd 广告;其它地区则显示 AdMob 广告。
部署广告函数
本函数在viewDidLoad()中调用,同时也可以在购买“广告去除”成功后调用:
- (void)disposeAds {
BOOL is_iAdON = NO;
BOOL is_adMobON = NO;
//分析设备可显示哪一家广告
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0) {
is_adMobON = YES;
if([[[UIDevicecurrentDevice] systemVersion] floatValue] >= 4.2f) {
//为iPad 4.2之后的系统显示iAd广告
//如果是北美国时间或太平洋时间,则假想是美国用户
//2010.12 英国,法国
//2011.1 德国
//2011.? 日本
if([[[NSTimeZonelocalTimeZone] name] rangeOfString:@"America/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Pacific/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Europe/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Asia/Tokyo"].location== 0)
{
is_adMobON = NO;
}
}
}
elseif([[[UIDevicecurrentDevice] systemVersion] floatValue] >= 4.0f) {
//如果是北美国时间或太平洋时间,则假想是美国用户
//2010.12 英国,法国
//2011.1 德国
//2011.? 日本
if([[[NSTimeZonelocalTimeZone] name] rangeOfString:@"America/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Pacific/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Europe/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Asia/Tokyo"].location== 0)
{
is_adMobON = NO;
}
else
is_adMobON = YES;
}
else
is_adMobON = YES;
if(!is_adMobON)
is_iAdON = YES;
//检测购买(这个为程序内购买了“去除广告”功能的把广告清除或是不显示,removeAdPurchased是个变量,本文未讨论)
if(removeAdPurchased) {
is_adMobON = NO;
is_iAdON = NO;
}
//打开广告
if(is_adMobON || is_iAdON) {
if(is_adMobON) {
//启用AdMob
if(!adMobAd) {
CGSize sizeToRequest;
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0)
sizeToRequest = CGSizeMake(748, 110);
else
sizeToRequest = CGSizeMake(320, 48);
adMobAd = [AdMobView requestAdOfSize:sizeToRequest withDelegate:self]; // start a new ad request
[adMobAdretain]; // this will be released when it loads (or fails to load)
}
}
else {
//启用iAd
if(!iAdView) {
iAdView= [[ADBannerViewalloc] initWithFrame:CGRectZero];
iAdView.requiredContentSizeIdentifiers= [NSSetsetWithObject: ADBannerContentSizeIdentifierPortrait];
iAdView.currentContentSizeIdentifier= ADBannerContentSizeIdentifierPortrait;
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0)
iAdView.frame = CGRectMake(0, 1024, 768, 66);
else
iAdView.frame = CGRectMake(0, 480, 320, 50);
iAdView.delegate = self;
[self.view addSubview:iAdView];
iAdView.hidden= YES; //暂时不显示广告框,收到广告后再显示出来
}
}
}
else{
//关闭广告
if(adMobAd) {
//关闭AdMob
[adMobAdremoveFromSuperview];
[adMobAd release];
adMobAd = nil;
}
else if(iAdView) {
//关闭iAd(bannerIsVisible是个变量,用于标识iAd广告是否已经显示内容,可不用)
if(bannerIsVisible) {
[UIViewbeginAnimations:@"animateAdBannerOff"context:NULL];
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0)
iAdView.frame = CGRectOffset(iAdView.frame, 0, 66);
else
iAdView.frame = CGRectOffset(iAdView.frame, 0, 50);
[UIViewcommitAnimations];
bannerIsVisible= NO;
iAdView.hidden = YES;
}
[iAdViewremoveFromSuperview];
[iAdView release];
iAdView = nil;
}
}
}
AdMob广告收到内容后处理函数:
// Sent when an ad request loaded an ad; this is a good opportunity to attach
// the ad view to the hierachy.
- (void)didReceiveAd:(AdMobView *)adView {
// get the view frame
CGRectframe = self.view.frame;
// put the ad at the bottom of the screen
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0)
adView.frame = CGRectMake((frame.size.width - 748)/2, frame.size.height - 110, 748, 110);
else
adView.frame = CGRectMake(0, frame.size.height - 48, frame.size.width, 48);
[self.viewaddSubview:adView];
[adMobRefreshTimerinvalidate];
adMobRefreshTimer= nil;
adMobRefreshTimer= [NSTimerscheduledTimerWithTimeInterval:AdMob_REFRESH_PERIODtarget:selfselector:@selector(refreshAdMob:) userInfo:nilrepeats:YES];
}
iAd广告收到内容后处理函数:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
if(!bannerIsVisible)
{
[UIViewbeginAnimations:@"animateAdBannerOn"context:NULL];
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0)
banner.frame = CGRectOffset(banner.frame, 0, -66);
else
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIViewcommitAnimations];
bannerIsVisible= YES;
banner.hidden = NO;
}
}
部署广告函数
本函数在viewDidLoad()中调用,同时也可以在购买“广告去除”成功后调用:
- (void)disposeAds {
BOOL is_iAdON = NO;
BOOL is_adMobON = NO;
//分析设备可显示哪一家广告
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0) {
is_adMobON = YES;
if([[[UIDevicecurrentDevice] systemVersion] floatValue] >= 4.2f) {
//为iPad 4.2之后的系统显示iAd广告
//如果是北美国时间或太平洋时间,则假想是美国用户
//2010.12 英国,法国
//2011.1 德国
//2011.? 日本
if([[[NSTimeZonelocalTimeZone] name] rangeOfString:@"America/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Pacific/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Europe/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Asia/Tokyo"].location== 0)
{
is_adMobON = NO;
}
}
}
elseif([[[UIDevicecurrentDevice] systemVersion] floatValue] >= 4.0f) {
//如果是北美国时间或太平洋时间,则假想是美国用户
//2010.12 英国,法国
//2011.1 德国
//2011.? 日本
if([[[NSTimeZonelocalTimeZone] name] rangeOfString:@"America/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Pacific/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Europe/"].location== 0
|| [[[NSTimeZonelocalTimeZone] name] rangeOfString:@"Asia/Tokyo"].location== 0)
{
is_adMobON = NO;
}
else
is_adMobON = YES;
}
else
is_adMobON = YES;
if(!is_adMobON)
is_iAdON = YES;
//检测购买(这个为程序内购买了“去除广告”功能的把广告清除或是不显示,removeAdPurchased是个变量,本文未讨论)
if(removeAdPurchased) {
is_adMobON = NO;
is_iAdON = NO;
}
//打开广告
if(is_adMobON || is_iAdON) {
if(is_adMobON) {
//启用AdMob
if(!adMobAd) {
CGSize sizeToRequest;
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0)
sizeToRequest = CGSizeMake(748, 110);
else
sizeToRequest = CGSizeMake(320, 48);
adMobAd = [AdMobView requestAdOfSize:sizeToRequest withDelegate:self]; // start a new ad request
[adMobAdretain]; // this will be released when it loads (or fails to load)
}
}
else {
//启用iAd
if(!iAdView) {
iAdView= [[ADBannerViewalloc] initWithFrame:CGRectZero];
iAdView.requiredContentSizeIdentifiers= [NSSetsetWithObject: ADBannerContentSizeIdentifierPortrait];
iAdView.currentContentSizeIdentifier= ADBannerContentSizeIdentifierPortrait;
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0)
iAdView.frame = CGRectMake(0, 1024, 768, 66);
else
iAdView.frame = CGRectMake(0, 480, 320, 50);
iAdView.delegate = self;
[self.view addSubview:iAdView];
iAdView.hidden= YES; //暂时不显示广告框,收到广告后再显示出来
}
}
}
else{
//关闭广告
if(adMobAd) {
//关闭AdMob
[adMobAdremoveFromSuperview];
[adMobAd release];
adMobAd = nil;
}
else if(iAdView) {
//关闭iAd(bannerIsVisible是个变量,用于标识iAd广告是否已经显示内容,可不用)
if(bannerIsVisible) {
[UIViewbeginAnimations:@"animateAdBannerOff"context:NULL];
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0)
iAdView.frame = CGRectOffset(iAdView.frame, 0, 66);
else
iAdView.frame = CGRectOffset(iAdView.frame, 0, 50);
[UIViewcommitAnimations];
bannerIsVisible= NO;
iAdView.hidden = YES;
}
[iAdViewremoveFromSuperview];
[iAdView release];
iAdView = nil;
}
}
}
AdMob广告收到内容后处理函数:
// Sent when an ad request loaded an ad; this is a good opportunity to attach
// the ad view to the hierachy.
- (void)didReceiveAd:(AdMobView *)adView {
// get the view frame
CGRectframe = self.view.frame;
// put the ad at the bottom of the screen
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0)
adView.frame = CGRectMake((frame.size.width - 748)/2, frame.size.height - 110, 748, 110);
else
adView.frame = CGRectMake(0, frame.size.height - 48, frame.size.width, 48);
[self.viewaddSubview:adView];
[adMobRefreshTimerinvalidate];
adMobRefreshTimer= nil;
adMobRefreshTimer= [NSTimerscheduledTimerWithTimeInterval:AdMob_REFRESH_PERIODtarget:selfselector:@selector(refreshAdMob:) userInfo:nilrepeats:YES];
}
iAd广告收到内容后处理函数:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
if(!bannerIsVisible)
{
[UIViewbeginAnimations:@"animateAdBannerOn"context:NULL];
if([[[UIDevicecurrentDevice] model] rangeOfString:@"iPad"].location== 0)
banner.frame = CGRectOffset(banner.frame, 0, -66);
else
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIViewcommitAnimations];
bannerIsVisible= YES;
banner.hidden = NO;
}
}
发表评论
-
iOS 监听音量调节 事件
2013-08-14 12:18 1076iOS 监听音量调节 事件 做项目需要音量调节的事件来控制其 ... -
viewDidUnload viewDidLoad UIViewController内存管理相关的几个方法
2012-08-23 01:52 1280viewDidUnload viewDidLoad UIVie ... -
cocoa 图片操作若干
2012-08-23 01:19 1146转载自 http://stackoverflow.com/qu ... -
Objective-C的Properties
2012-08-21 18:20 1676Objective-C是苹果为Cocoa框架下设计的面向对象语 ... -
objective-c properties 概念
2012-08-21 17:50 800学了一段时间 objective-c properties 概 ... -
UIVideoEditorController 使用
2012-07-18 15:15 1679概述 不能定制界面,不可派生子类。 使用步骤: 检查制定源是否 ... -
iphone app 四种崩溃类型
2012-07-17 22:42 1145一.四种崩溃类型 程序崩溃: 可能是最常见的,经常发生于内存 ... -
首先查看crash log中的崩溃线程
2012-07-15 15:47 1869首先查看crash log中的崩溃线程,假如是这样的: Th ... -
iOS【EXC_BAD_ACCESS 】crash报告分析
2012-07-15 15:40 7936做iOS的开发者,经常都会遇到这个问题,我在这里做一下简单的分 ... -
objective-c aes加密
2012-05-11 11:21 3615在cocoa看到的加密代码,介绍一下。 aes加密的,1M的数 ... -
NSObject类所支持的一些基本方法
2012-04-10 14:33 1361NSObject类所支持的一些基本方法 对象是否class- ... -
关于出现僵尸信号SIGBAT或者EXC_BAD_ACCESS的解决方案
2012-03-31 11:52 2220关于出现僵尸信号SIGBAT或者EXC_BAD_ACCESS的 ... -
Xcode4.2新特性之storyboards (故事板)
2012-03-31 11:43 4345Xcode4.2新特性之storyboards ... -
iPhone OS体系结构
2012-03-29 07:43 1670iPhone OS体系结构 iPhone OS有着绚丽优雅的外 ... -
iPhone的软件栈分成好几层
2012-03-29 07:01 1217iPhone的软件栈分成好几层。应用程序位于最高的抽象层,而系 ... -
UIImagePickerController使用
2012-03-17 22:47 4284UIImagePickerController使用 引用UI ... -
wait_fences: failed to receive reply: 10004003奇怪的错误
2012-03-17 11:09 2745今日遇到wait_fences: failed to rece ... -
iphone app 本地化程序名称
2012-03-17 01:38 924本地化程序名称 1、 建立InfoPlist.strings ... -
iphone app 为图片添加边框
2012-03-17 01:30 2522头文件中#import <QuartzCore/Quar ... -
objective-c 内存管理的文章摘录2
2012-03-15 01:09 873Cocoa内存管理规则 1)当 ...
相关推荐
iphone去广告时钟
目录 ►前言 ►第一部分:市场分析 ►第二部分:广告策略与计划 ►第三部分:广告效果预测和监控 ►附录 ...iPhone引入了基于大型多触点显示屏和领先性新软件的全新用户界面,让用户用手指即可控制iPhone
iphone-pdf以图片形式显示
想在普通电脑上让你发表的空间说说显示来自iPhone嘛?火狐专用浏览器就可以实现这个效果!不但可以显示发布的说说来自iPhone触屏版,还可以显示iPad或android,绝对给力,不管你信不信,反正我是信了,我已经测试100%...
此软件上QQ可显示QQ for pad 在线,发消息可显示来自iphone 5。
非常漂亮的仿iPhone图片切换效果
电脑显示iphone,ipad QQ在线
iPhone QQ头像生成器 显示iphone在线 不用手机 超绝!
iphone自定义广告栏,UIScrollView ,UIPageController
详细的解释可以在这里看到:http://blog.csdn.net/comeontom/article/details/7563484。
iPhone XS 显示原理,维修技术人员提高必备,需者自取!
NSDate,iphone显示时间,日期的方法集合
Iphone5广告策划方案
显示iphone在线
jQuery模仿iPhone手机的天气预报显示效果,模拟 ios 天气显示功能,仿iphone(苹果)手机(或Android系统手机)的天气预报显示效果,带动画效果的天气显示功能,非常的漂亮,天气背景是动态的效果组合,看上去想当...
iPhone狂:约会iPhone
IPhone弹出基于Phonegap的工程的Admob广告
新浪微博,安卓手机上显示是IPHONE的。
安卓qq显示iphone在线可以让您的QQ号码显示iPhone QQ在线标志! 不管你是什么机子都可以显示iphone在线样式,使用,绝对是吊丝装X之必备神器。登陆成功后,好友马上能看到iphone在线标