開始要製作免費版的APP,因為是在沒有人贊助的情況下來開發,為了有些許微薄的收入,決定在APP中內嵌入廣告,查詢過網路上有經驗的開發者的文章,發現使用AdMob行動廣告是較有益處!因為它已被Google給買下來⋯⋯此教學是使用AdMob SDK 6.8.0。
AdMob後台可以設定廣告背景和文字的顏色,因為我要測試效果,所以就從預設黑色設定為亮粉色囉!
- 首先就是要去AdMob申請帳號,接著取得發佈商ID。
- 下載好AdMob SDK,將相關檔案匯入我們的專案中。
- 加入相關的Framework:
- AdSupport
- AudioToolbox
- AVFoundation
- CoreGraphics
- CoreTelephony
- MessageUI
- StoreKit
- SystemConfiguration
- 撰寫相關程式碼
/** Theme: Using AdMob IDE: Xcode 5 Language: Objective C Date: 103/04/04 Author: HappyMan Blog: https://cg2010studio.wordpress.com/ */ // .h中 #import <UIKit/UIKit.h> #import "GADBannerView.h" #import "GADInterstitial.h" @interface HTAdMobViewController : UIViewController <GADBannerViewDelegate, GADInterstitialDelegate> { GADBannerView *happyBannerView; IBOutlet UIView *bannerView; GADInterstitial *happyInterstitial; } // .m中 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. // Create a view of the standard size at the top of the screen. // Available AdSize constants are explained in GADAdSize.h. happyBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; // Specify the ad unit ID. happyBannerView.adUnitID = @"a15353d0bba1484"; // Let the runtime know which UIViewController to restore after taking // the user wherever the ad goes and add it to the view hierarchy. happyBannerView.rootViewController = self; happyBannerView.delegate = self; [bannerView addSubview:happyBannerView]; } #pragma mark GADRequest generation - (GADRequest *)request { GADRequest *request = [GADRequest request]; // Make the request for a test ad. Put in an identifier for the simulator as well as any devices // you want to receive test ads. request.testDevices = @[ // TODO: Add your device/simulator test identifiers here. Your device identifier is printed to // the console when the app is launched. // GAD_SIMULATOR_ID ]; return request; } #pragma mark GADBannerViewDelegate implementation - (void)adViewDidReceiveAd:(GADBannerView *)view { NSLog(@"Received ad successfully"); } - (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error { NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]); } #pragma mark GADInterstitialDelegate implementation - (void)interstitialDidReceiveAd:(GADInterstitial *)ad { NSLog(@"Received ad successfully"); [happyInterstitial presentFromRootViewController:self]; } - (void)interstitial:(GADInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error { NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]); } -(IBAction)refreshButtonCLicked:(UIButton *)button { // Initiate a generic request to load it with an ad. [happyBannerView loadRequest:[self request]]; happyInterstitial = [[GADInterstitial alloc] init]; happyInterstitial.delegate = self; happyInterstitial.adUnitID = @"a15333bad89ff03"; [happyInterstitial loadRequest:[self request]]; } // AppDelegate.m裡寫載入APP時馬上顯示廣告 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { GADInterstitial *splashInterstitial_ = [[GADInterstitial alloc] init]; splashInterstitial_.adUnitID = @"a15353d0bba1484"; [splashInterstitial_ loadAndDisplayRequest:[GADRequest request] usingWindow:self.window initialImage:[UIImage imageNamed:@“happy_ban.png"]];// 還未載入廣告前的影像 }
之前測試幾乎都會顯示魔神之塔的廣告,四月之後它改到5.0版~點擊後去後台查看,可發現數據有在變化,據有經驗人士所述:
- 行動廣告AdMob(Google):大約0.005~0.03美元每則點擊
- 網頁廣告AdSense(Google):大約0.17~0.3每則點擊
咱們就來開發許多人會使用的APP,如此使用者一旦量大,我們的收益也跟著多喲!
若讀者還沒申請到發佈商ID,我的(見程式碼)可以先拿去測試喔!若本篇文章對你有些許助益,也可以多按廣告贊助,甘恩:)
2015/01/08更新
Admob在2014/09有重大更新,請自行至官網了解喔!
參考:
- AdMob官方網站
- [APP開發] 將AdMob廣告加入iPhone應用程式中
- [iOS/Objective-C][在APP加上AdMob廣告]
- 在台灣使用AdMob的經驗
- [專題]漫談行動廣告之 5:一定要知道的行動廣告(Mobile Ads)平台:AdMob、iAD、Facebook 與 Twitter
- AdMob 的廣告收入分析參考
- App收益-廣告(Admob)
- 20121129 AdMob合作夥伴日聽後心得
- 【分享】- AdMob 付款到 PayPal 並提領到「台灣的銀行」 全記錄
- 官方橫幅廣告教學(中文)
- 官方橫幅廣告教學(英文)
- 官方插頁廣告教學(中文)
- 官方插頁廣告教學(英文)
Comments on: "[iOS] 使用AdMob行動廣告教學" (6)
請問我在填寫Admob的付款資料,要打郵遞區號時,沒有台灣的郵遞區號可以選擇, 這情況要如何解決? 謝謝您的協助.
讚讚
有截圖嗎?我進去Admob,「付款」有要寫地址,郵遞區號是自己打的不是用選擇的喔~
讚讚
謝謝回覆. 我是自己打的, 汐止是22187, 但出現系統無法辨識此郵遞區號格式, 所以我才按它旁邊的查訊, 但連結至大陸的中國郵政, 那網站是沒有台灣的郵遞區號.
讚讚
請教一下
在開發中如何知道我寫的程式可以正確拿到廣告呢?
還是說只要拿得到測試用廣告 就表示上架後可以拿到我設定的 Ad unit ?
(這是我的猜測)
謝謝你的回覆
讚讚
請看官方文件,應有區分開發時測試的廣告,和上架時正式發送的廣告。
讚讚
Reblogged this on 逍遙文工作室 and commented:
三年後,再次使用Admob放廣告,SDK有不少更新,有多兩個廣告可供選擇,現在共有四種廣告,可依據使用者介面來顯示。
讚讚