`
bengan
  • 浏览: 206661 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

iPhone上根据不同的国家显示广告

 
阅读更多
本段教程和代码例子由 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;
    }
}
分享到:
评论

相关推荐

    Iphone5广告策划方案.zip

    针对不同国家和地区,广告内容会有所调整,以适应当地的文化背景和消费者习惯,确保信息传递的有效性和共鸣。 总结起来,iPhone5的广告策划方案充分体现了苹果公司的品牌策略和市场洞察力。通过精准定位、情感营销...

    辽宁省大石桥市第二高级中学2017_2018学年高二英语下学期学考模拟考试试题

    虽然它们都提供了大量的歌曲,但并不是所有服务都是完全免费的,部分服务在免费版本中会显示广告,或者在免费试用期后需要付费订阅。此外,Apple Music和Live365在特定方面有所区别,如Apple Music有语音助手功能,...

    2017今日头条房产行业用户数据报告

    在手机品牌的选择上,数据显示iPhone领衔,国产品牌如小米、华为占据领先,而老牌三星仍位居前列。这些信息对移动广告平台尤为重要,可以帮助广告商在不同品牌手机上进行广告定位。 5. 用户分享行为对内容推广的...

    汽车品牌内容营销专题报告.pptx

    根据中国汽车工业协会的数据,2001年至2017年间,中国汽车销量虽保持增长,但年均增速逐渐下滑,2017年上半年至2018年上半年的无效流量占比高达46.15%,反映出广告效果的减弱。 在这样的背景下,女性消费者成为了...

    移动互联网电子商务的研究报告

    尤其是北美、欧洲和亚太地区的市场表现尤为突出,其中亚太地区营收同比增长高达151%,显示出中国和亚洲其他国家对移动互联网的接纳速度之快。 在中国,移动互联网市场规模正以惊人的速度增长,年均复合增长率达到了...

    2024年鱼露行业市场分析.pptx

    特别在欧美国家,鱼露逐渐被接受并融入当地饮食文化。 - **技术创新助力市场发展**:现代生产技术如低温发酵技术的应用,使得鱼露品质更加稳定,口感更佳。这些技术创新不仅提高了鱼露的生产效率,还为其在全球市场...

    四川省成都市2017_2018学年高二英语上学期期中试题

    2. **市场营销策略**:广告中提到的每月不同主题和特别嘉宾(如Sanji Ali),吸引不同兴趣的人群参与,同时提供优惠和赠品(如签名足球和触控笔)来增加活动吸引力。 3. **品牌合作**:MEELO作为赞助商,通过活动...

    互联网女皇发布互联网新趋势报告

    6. 互联网广告与经济趋势:尽管互联网广告支出与用户在互联网上所花费的时间大致对等,但经济趋势却表现出不确定性,部分股市表现不佳,消费者信心接近4年高点但仍低于长期平均水平。经济的不确定性可能对互联网行业...

Global site tag (gtag.js) - Google Analytics