在iPhone程序中集成iAd广告

移动开发 iOS
Iava的执行文件包括lav和iad两个,iad是lav文件的认证文件,没有iad将无法使用lav的全部功能。

iPhone程序中集成iAd广告 是本文要介绍的内容,iAd的推出无疑给Iphone/IPad的应用程序开发者打开了另一条创收之门,前不久,美国的一位开发者Json Ting开发的将相机闪光灯转为手电筒的应用,集成iAd后在***天就给他带来了1400$的广告收入。我将在这篇文章中讲讲如何把iAd集成到你的应用程序中。另外也会提到集成中可能遇到的一些问题:

如何支持横屏跟竖屏。

如何保持与os 3.0的后向兼容。

与UITableViewController的集成。

1、将Base SDK设为4.0, 将Deployment target设为3.0. 如图所示:

2、链接iAd Framework.

右击Frameworks, 选择"Add\Existing Frameworks", 添加"iAd.framework". 但是在没有iAd.framework的机器上,比如3.x版本的,这样会Crash.所以要把这个链接变为weak link. 在"targets"中右击你的工程,然后"Get Info", 在Linking\Other Linker Flags里添加"-weak_framework iAd". 这样就能够保证程序的后向兼容性。

3、在XIB中加入你的UI

可以考虑把其它功能性的UI加在一个父亲UIView,后面把iAd跟这个父亲UIView作为同一级,这样iAd显示时不会影响原有UI。

4、与UIViewController的集成

(1)获取iAd Banner大小的帮助函数(见示例).

(2)创建iAd Banner的函数.

  1. - (void)createAdBannerView   
  2.  {  
  3.     Class classAdBannerView = NSClassFromString(@"ADBannerView");   
  4.    if (classAdBannerView != nil)   
  5.     { ...  
  6.     }  

这个地方使用NSClassFromString 能够保证代码的后向兼容性,在os 3.x的系统上这个函数不会成功,iAd不会显示,但是程序仍然能够运行.

(4) 调整功能性UI及iAd Banner的位置的函数。(见代码示例 fixupAdView)

(5)在合适时机创建和调整iAd Banner位置。

  1. - (void)viewDidLoad   
  2. {  
  3.    [self createAdBannerView];  
  4. }  
  5. - (void) viewWillAppear:(BOOL)animated   
  6. {  
  7.   [self refresh];  
  8.   [self fixupAdView:[UIDevice currentDevice].orientation];  
  9. }  
  10. - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation   
  11.    duration:(NSTimeInterval)duration  
  12. {  
  13.   [self fixupAdView:toInterfaceOrientation];  
  14. }  
  15.  
  16. 4.5 实现ADBannerViewDelegate  
  17.  
  18. - (void)bannerViewDidLoadAd:(ADBannerView *)banner   
  19. {  
  20.   if (!_adBannerViewIsVisible)   
  21.   {   
  22.      _adBannerViewIsVisible = YES;  
  23.      [self fixupAdView:[UIDevice currentDevice].orientation];  
  24.   }  
  25. }  
  26.  - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error  
  27. {  
  28.   if (_adBannerViewIsVisible)  
  29.   {   
  30.      _adBannerViewIsVisible = NO;  
  31.      [self fixupAdView:[UIDevice currentDevice].orientation];  
  32.   }  

5、 与UITableViewController的集成(更新中)

代码示例

小结:在IPhone程序中集成iAd广告 的内容介绍完了,希望本文对你有所帮助。

本文来自:http://www.cnblogs.com/MobileDevelop/archive/2010/07/17/1779133.html

责任编辑:zhaolei 来源: 互联网
相关推荐

2009-06-23 09:33:20

FCKEditorJSFJSP

2009-06-01 16:18:30

SpringJPA集成

2009-01-03 15:01:16

ibmdwLptus

2009-01-03 14:43:55

ibmdwPHPsMash

2011-06-29 09:42:12

Visual Stud Qt Opensource

2014-09-28 14:53:39

渗透BurpSuiteSqlmap

2013-06-04 13:26:02

2016-04-20 09:47:40

MapBoxAndroid地图

2009-06-11 13:28:18

Glassfish集成

2012-10-18 10:12:42

IBMdw

2011-03-04 09:40:42

AJAX开发集成数据库

2024-01-31 09:42:11

RabbitMQ消息队列.NET

2023-03-13 00:16:28

2011-03-02 17:42:35

2011-08-23 09:50:29

LuaPlusLua 脚本

2018-01-02 08:30:45

IntelCPU

2014-12-31 09:56:29

Ehcache

2011-07-06 14:22:52

iPhone Push

2012-04-26 13:30:05

iPhoneApp Store发布程序

2021-11-01 14:52:38

ElasticSear索引SQL
点赞
收藏

51CTO技术栈公众号