如何在IPhone程式中整合iAd廣告

來源:互聯網
上載者:User
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的整合4.1 擷取iAd Banner大小的協助函數(見樣本). 4.2 建立iAd
Banner的函數.
- (void)createAdBannerView  {    Class classAdBannerView = NSClassFromString(@"ADBannerView");    if (classAdBannerView != nil)     { ...    }}

這個地方使用NSClassFromString 能夠保證代碼的回溯相容性,在os
3.x的系統上這個函數不會成功,iAd不會顯示,但是程式仍然能夠運行.

4.3 調整功能性UI及iAd
Banner的位置的函數。(見程式碼範例 fixupAdView)4.4 在合適時機建立和調整iAd Banner位置。
- (void)viewDidLoad {   [self createAdBannerView];}
- (void) viewWillAppear:(BOOL)animated {  [self refresh];  [self fixupAdView:[UIDevice currentDevice].orientation];}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation    duration:(NSTimeInterval)duration{  [self fixupAdView:toInterfaceOrientation];}

4.5 實現ADBannerViewDelegate
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {  if (!_adBannerViewIsVisible)   {      _adBannerViewIsVisible = YES;     [self fixupAdView:[UIDevice currentDevice].orientation];  }}
 - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{  if (_adBannerViewIsVisible)  {      _adBannerViewIsVisible = NO;     [self fixupAdView:[UIDevice currentDevice].orientation];  }}


5) 與UITableViewController的整合(更新中)程式碼範例

參考:

1)http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-app

2)http://www.cocoachina.com/bbs/read.php?tid=23465

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.