檢視 AdMob Mediation Video 的原始碼
←
AdMob Mediation Video
跳至導覽
跳至搜尋
由於下列原因,您沒有權限進行編輯此頁面的動作:
您請求的操作只有這個群組的使用者能使用:
使用者
您可以檢視並複製此頁面的原始碼。
首先將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 Video View == '''// TADCustomVideo.h''' '''// 匯入 TAMedia SDK 定義''' #import "TADVideoAdView.h" #import "TADVideoAdViewDelegate.h" '''// 匯入 Admob SDK 定義''' #import "GADCustomEventBanner.h" #import "GADCustomEventBannerDelegate.h" @interface TADCustomVideo : NSObject<GADCustomEventBanner, TADVideoAdViewDelegate> { TADVideoAdView *_videoView; } @property (nonatomic, weak) id<GADCustomEventBannerDelegate> delegate; @end '''// TADCustomVideo.m''' #import "TADCustomVideo.h" @interface TADCustomVideo () { UIView *tempView; } @end @implementation TADCustomVideo @synthesize delegate = _delegate; - (void)requestBannerAd:(GADAdSize)adSize parameter:(NSString *)serverParameter label:(NSString *)serverLabel request:(GADCustomEventRequest *)customEventRequest { '''// 將 GADCustomEventRequest 物件裡的資訊轉入 TADRequest 物件''' TADRequest *tadRequest = [TADRequest request]; tadRequest.testing = customEventRequest.isTesting; tadRequest.gender = (TADGender)customEventRequest.userGender; tadRequest.birthday = customEventRequest.userBirthday; [tadRequest setLocationWithLatitude:customEventRequest.userLatitude longitude:customEventRequest.userLongitude accuracy:customEventRequest.userLocationAccuracyInMeters]; '''// bannerView 物件初始化, 帶入自訂的origin''' if (_videoView == nil) { _videoView = [[TADVideoAdView alloc] initWithVideoAd]; } '''// 必須要設定delegate''' _videoView.delegate = self; '''// serverParameter 為 AD Unit ID, 在 Admob 裡設定''' _videoView.adUnitID = serverParameter; '''// 載入廣告''' [_videoView loadRequest:tadRequest]; } #pragma mark - #pragma mark - TADBannerViewDelegate - (void)adViewDidReceiveAd:(TADVideoAdView *)view { NSLog(@"CustomBanner - didReceived! View: %@", view); '''// 回傳成功地收到廣告''' '''// (回傳和 videoView 一樣大小的 UIView 物件給 customEventBanner)''' tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 250)]; [_delegate customEventBanner:self didReceiveAd:tempView]; '''// 將 (TADVideoAdView *)view 的 reference 傳回呼叫 mediation 的 view controller''' '''// 這裡呼叫 mediation 的 view controller 是 MediationViewController''' ((MediationViewController *)[_delegate viewControllerForPresentingModalView]).videoView = view; '''// 將 videoView 的 delegate 設為不是 self 的物件, 以免 custom 物件比 video 更早被 dealloc''' view.delegate = [_delegate viewControllerForPresentingModalView]; } - (void)adView:(TADVideoAdView *)view didFailToReceiveAdWithError:(NSError *)error { [_delegate customEventBanner:self didFailAd:error]; } - (void)adViewWillDismissScreen:(TADVideoAdView *)adView { [_delegate customEventBannerWillDismissModal:self]; } - (void)adViewDidDismissScreen:(TADVideoAdView *)adView { [_delegate customEventBannerDidDismissModal:self]; } @end [[IOS SDK 2.0 Developer Guide|Back]]
返回到「
AdMob Mediation Video
」。
導覽選單
個人工具
登入
命名空間
頁面
討論
變體
已展開
已摺疊
視圖
閱讀
檢視原始碼
檢視歷史
更多
已展開
已摺疊
搜尋
導覽
首頁
近期變更
隨機頁面
有關 MediaWiki 的說明
工具
連結至此的頁面
相關變更
特殊頁面
頁面資訊