- 浏览: 206661 次
- 性别:
- 来自: 广州
-
文章分类
最新评论
-
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 1139iOS 监听音量调节 事件 做项目需要音量调节的事件来控制其 ... -
viewDidUnload viewDidLoad UIViewController内存管理相关的几个方法
2012-08-23 01:52 1367viewDidUnload viewDidLoad UIVie ... -
cocoa 图片操作若干
2012-08-23 01:19 1189转载自 http://stackoverflow.com/qu ... -
Objective-C的Properties
2012-08-21 18:20 1716Objective-C是苹果为Cocoa框架下设计的面向对象语 ... -
objective-c properties 概念
2012-08-21 17:50 863学了一段时间 objective-c properties 概 ... -
UIVideoEditorController 使用
2012-07-18 15:15 1769概述 不能定制界面,不可派生子类。 使用步骤: 检查制定源是否 ... -
iphone app 四种崩溃类型
2012-07-17 22:42 1225一.四种崩溃类型 程序崩溃: 可能是最常见的,经常发生于内存 ... -
首先查看crash log中的崩溃线程
2012-07-15 15:47 2005首先查看crash log中的崩溃线程,假如是这样的: Th ... -
iOS【EXC_BAD_ACCESS 】crash报告分析
2012-07-15 15:40 8031做iOS的开发者,经常都会遇到这个问题,我在这里做一下简单的分 ... -
objective-c aes加密
2012-05-11 11:21 3662在cocoa看到的加密代码,介绍一下。 aes加密的,1M的数 ... -
NSObject类所支持的一些基本方法
2012-04-10 14:33 1425NSObject类所支持的一些基本方法 对象是否class- ... -
关于出现僵尸信号SIGBAT或者EXC_BAD_ACCESS的解决方案
2012-03-31 11:52 2675关于出现僵尸信号SIGBAT或者EXC_BAD_ACCESS的 ... -
Xcode4.2新特性之storyboards (故事板)
2012-03-31 11:43 4404Xcode4.2新特性之storyboards ... -
iPhone OS体系结构
2012-03-29 07:43 1823iPhone OS体系结构 iPhone OS有着绚丽优雅的外 ... -
iPhone的软件栈分成好几层
2012-03-29 07:01 1293iPhone的软件栈分成好几层。应用程序位于最高的抽象层,而系 ... -
UIImagePickerController使用
2012-03-17 22:47 4333UIImagePickerController使用 引用UI ... -
wait_fences: failed to receive reply: 10004003奇怪的错误
2012-03-17 11:09 2804今日遇到wait_fences: failed to rece ... -
iphone app 本地化程序名称
2012-03-17 01:38 1018本地化程序名称 1、 建立InfoPlist.strings ... -
iphone app 为图片添加边框
2012-03-17 01:30 2615头文件中#import <QuartzCore/Quar ... -
objective-c 内存管理的文章摘录2
2012-03-15 01:09 914Cocoa内存管理规则 1)当 ...
相关推荐
针对不同国家和地区,广告内容会有所调整,以适应当地的文化背景和消费者习惯,确保信息传递的有效性和共鸣。 总结起来,iPhone5的广告策划方案充分体现了苹果公司的品牌策略和市场洞察力。通过精准定位、情感营销...
虽然它们都提供了大量的歌曲,但并不是所有服务都是完全免费的,部分服务在免费版本中会显示广告,或者在免费试用期后需要付费订阅。此外,Apple Music和Live365在特定方面有所区别,如Apple Music有语音助手功能,...
在手机品牌的选择上,数据显示iPhone领衔,国产品牌如小米、华为占据领先,而老牌三星仍位居前列。这些信息对移动广告平台尤为重要,可以帮助广告商在不同品牌手机上进行广告定位。 5. 用户分享行为对内容推广的...
根据中国汽车工业协会的数据,2001年至2017年间,中国汽车销量虽保持增长,但年均增速逐渐下滑,2017年上半年至2018年上半年的无效流量占比高达46.15%,反映出广告效果的减弱。 在这样的背景下,女性消费者成为了...
尤其是北美、欧洲和亚太地区的市场表现尤为突出,其中亚太地区营收同比增长高达151%,显示出中国和亚洲其他国家对移动互联网的接纳速度之快。 在中国,移动互联网市场规模正以惊人的速度增长,年均复合增长率达到了...
特别在欧美国家,鱼露逐渐被接受并融入当地饮食文化。 - **技术创新助力市场发展**:现代生产技术如低温发酵技术的应用,使得鱼露品质更加稳定,口感更佳。这些技术创新不仅提高了鱼露的生产效率,还为其在全球市场...
2. **市场营销策略**:广告中提到的每月不同主题和特别嘉宾(如Sanji Ali),吸引不同兴趣的人群参与,同时提供优惠和赠品(如签名足球和触控笔)来增加活动吸引力。 3. **品牌合作**:MEELO作为赞助商,通过活动...
6. 互联网广告与经济趋势:尽管互联网广告支出与用户在互联网上所花费的时间大致对等,但经济趋势却表现出不确定性,部分股市表现不佳,消费者信心接近4年高点但仍低于长期平均水平。经济的不确定性可能对互联网行业...