檢視 AdMob Mediation 的原始碼
←
AdMob Mediation
跳至導覽
跳至搜尋
由於下列原因,您沒有權限進行編輯此頁面的動作:
您請求的操作只有這個群組的使用者能使用:
使用者
您可以檢視並複製此頁面的原始碼。
首先將AdMob和TAMedia SDK整合至專案中,AdMob SDK可以在這裡下載 https://developers.google.com/mobile-ads-sdk/download?#downloadios。<br> 接著在AdMob Mediation新增Custom Event(https://mediation.admob.com)。<br> 新增Custom Event的詳細說明可以參考https://developers.google.com/mobile-ads-sdk/docs/admob/mediation#ios。<br> 最後,在專案中加入與Custom Event對應的Class,其中Custom Event的Class Name需要和新增的Class Name保持一致,例如Custom Event的Class Name是TADCustomView,則新增的Class Name也必須為TADCustomView。 == Custom Banner View == // TADCustomBanner.m '''// 匯入需要的 .h 檔''' #import "TADCustomBanner.h" #import "GADCustomEventBanner.h" #import "GADCustomEventBannerDelegate.h" #import "TADBannerView.h" #import "TADRequest.h" #import "TADMediationView.h" @interface TADCustomBanner () <TADBannerViewDelegate> { '''// 這裡需要使用 TADMediationView 物件!!!''' TADMediationView *_bannerView; } @end @implementation TADCustomBanner @synthesize delegate = _delegate; - (void)requestBannerAd:(GADAdSize)adSize parameter:(NSString *)serverParameter label:(NSString *)serverLabel request:(GADCustomEventRequest *)request { // TODO: Use the parameters and self.delegate to make a banner request to your // ad network. Remember to set this class to be your banner’s delegate. TADRequest *tadRequest = [TADRequest request]; '''// 設定非測試模式''' tadRequest.testing = NO; '''// 設定 Geolocation 資訊''' [tadRequest setLocationWithLatitude:25.0265954 longitude:121.5540628 accuracy:53.996]; if (_bannerView == nil) { _bannerView = [[TADMediationView alloc] initWithAdSize:kTADAdSizeBanner]; _bannerView.delegate = self; _bannerView.adUnitID = serverParameter; _bannerView.rootViewController = [_delegate viewControllerForPresentingModalView]; } [_bannerView loadRequest:tadRequest]; } #pragma mark - #pragma mark - TADBannerViewDelegate - (void)adViewDidReceiveAd:(TADBannerView *)view { [self.delegate customEventBanner:self didReceiveAd:view]; } - (void)adView:(TADBannerView *)view didFailToReceiveAdWithError:(NSError *)error { [self.delegate customEventBanner:self didFailAd:error]; } - (void)dealloc{ '''// 記得要設為 nil''' if (_bannerView != nil) { _bannerView.delegate = nil; _bannerView = nil; } } @end == Custom Interstitial View == // TADCustomInterstitial.m '''// 匯入需要的 .h 檔''' #import "TADCustomInterstitial.h" #import "GADCustomEventInterstitial.h" #import "GADCustomEventInterstitialDelegate.h" #import "TADInterstitial.h" #import "TADRequest.h" @interface TADCustomInterstitial () <TADInterstitialDelegate> { '''// 使用原本 Interstitial 物件即可''' TADInterstitial *_interstitialView; } @end @implementation TADCustomInterstitial - (void)requestInterstitialAdWithParameter:(NSString *)serverParameter label:(NSString *)serverLabel request:(GADCustomEventRequest *)customEventRequest { TADRequest *tadRequest = [TADRequest request]; '''// 設定非測試模式''' tadRequest.testing = NO; '''// 設定 Geolocation 資訊''' [tadRequest setLocationWithLatitude:25.0265954 longitude:121.5540628 accuracy:53.996]; if (!_interstitialView) { _interstitialView = [[TADInterstitial alloc] init]; _interstitialView.delegate = self; _interstitialView.adUnitID = serverParameter; } [_interstitialView loadRequest:tadRequest]; } - (void)presentFromRootViewController:(UIViewController *)rootViewController { [_interstitialView presentFromRootViewController:rootViewController]; } #pragma mark - #pragma mark - TADInterstitialDelegate - (void)interstitialDidReceiveAd:(TADInterstitial *)ad { NSLog(@"[Test App] interstitialDidReceiveAd:%@", ad); [self presentFromRootViewController:nil]; } - (void)interstitial:(TADInterstitial *)ad didFailToReceiveAdWithError:(TADRequestError *)error { NSLog(@"[Test App] didFailToReceiveAdWithError:%@ %@", ad, error); } - (void)interstitialWillPresentScreen:(TADInterstitial *)ad { NSLog(@"[Test App] interstitialWillPresentScreen:%@", ad); } - (void)interstitialWillDismissScreen:(TADInterstitial *)ad { NSLog(@"[Test App] interstitialWillDismissScreen:%@", ad); } - (void)interstitialDidDismissScreen:(TADInterstitial *)ad { NSLog(@"[Test App] interstitialDidDismissScreen:%@", ad); //_interstitialView.delegate = nil; //_interstitialView = nil; } - (void)interstitialWillLeaveApplication:(TADInterstitial *)ad { NSLog(@"[Test App] interstitialWillLeaveApplication:%@", ad); } - (void)dealloc { '''// 記得要設為 nil''' if (_interstitialView) { _interstitialView.delegate = nil; _interstitialView = nil; } } @end
返回到「
AdMob Mediation
」。
導覽選單
個人工具
登入
命名空間
頁面
討論
變體
已展開
已摺疊
視圖
閱讀
檢視原始碼
檢視歷史
更多
已展開
已摺疊
搜尋
導覽
首頁
近期變更
隨機頁面
有關 MediaWiki 的說明
工具
連結至此的頁面
相關變更
特殊頁面
頁面資訊