「Integration with AdMob Mediation」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser (新頁面: 首先將AdMob和TAMedia SDK整合至專案中,AdMob SDK可以在這裡下載https://developers.google.com/mobile-ads-sdk/download。<br> 接著在AdMob Mediation新增Custom Event...) |
imported>Wikiuser |
||
行 70: | 行 70: | ||
request:(GADCustomEventRequest *)customEventRequest { | request:(GADCustomEventRequest *)customEventRequest { | ||
CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, [UIScreen mainScreen].applicationFrame.size.height); | CGRect frame = CGRectMake(0, 0, | ||
[UIScreen mainScreen].applicationFrame.size.width, [UIScreen mainScreen].applicationFrame.size.height); | |||
adView = [[TWMTAMediaInterstitialView alloc] initWithFrame:frame | adView = [[TWMTAMediaInterstitialView alloc] initWithFrame:frame | ||
slotId:serverParameter | slotId:serverParameter |
於 2014年1月28日 (二) 04:25 的最新修訂
首先將AdMob和TAMedia SDK整合至專案中,AdMob SDK可以在這裡下載https://developers.google.com/mobile-ads-sdk/download。
接著在AdMob Mediation新增Custom Event(https://mediation.admob.com)。
新增Custom Event的詳細說明可以參考https://developers.google.com/mobile-ads-sdk/docs/admob/mediation#ios。
最後,在專案中加入與Custom Event對應的Class,其中Custom Event的Class Name需要和新增的Class Name保持一致,例如Custom Event的Class Name是TWMTAMediaCustomView,則新增的Class Name也必須為TWMTAMediaCustomView。
Banner廣告
#import "TWMTAMediaCustomView.h" #import "GADCustomEventBanner.h" #import "GADCustomEventBannerDelegate.h" #import "TWMTAMediaView.h" @interface TWMTAMediaCustomView () <GADCustomEventBanner, TWMTAMediaViewDelegate> { TWMTAMediaView *adView; } @end @implementation TWMTAMediaCustomView @synthesize delegate; - (void)requestBannerAd:(GADAdSize)adSize parameter:(NSString *)serverParameter label:(NSString *)serverLabel request:(GADCustomEventRequest *)customEventRequest { CGRect frame = CGRectMake(0, 0, adSize.size.width, adSize.size.height); adView = [[TWMTAMediaView alloc] initWithFrame:CGRectMake(0, 0, 320, 50) slotId:serverParameter developerID:@"" gpsEnabled:YES testMode:NO]; adView.delegate = self; [adView receiveAd]; } - (void)viewWillLoadAd:(TWMTAMediaView *)view { NSLog(@"%@ viewWillLoadAd", view); [self.delegate customEventBanner:self didReceiveAd:view]; } - (void)viewDidLoadAd:(TWMTAMediaView *)view { NSLog(@"%@ viewDidLoadAd", view); [self.delegate customEventBanner:self didReceiveAd:view]; } - (void)view:(TWMTAMediaView *)view didFailToReceiveAdWithError:(NSError *)error { NSLog(@"%@ didFailToReceiveAdWithError:%@", view, error.description); [self.delegate customEventBanner:self didFailAd:error]; } - (BOOL)viewActionShouldBegin:(TWMTAMediaView *)view willLeaveApplication:(BOOL)willLeave { NSLog(@"%@ willLeaveApplication:%i", view, willLeave); [self.delegate customEventBannerWillLeaveApplication:self]; return YES; } @end
Interstitial廣告
#import "TWMTAMediaCustomInterstitialView.h" #import "GADCustomEventInterstitial.h" #import "GADCustomEventInterstitialDelegate.h" #import "TWMTAMediaInterstitialView.h" @interface TWMTAMediaCustomInterstitialView () <GADCustomEventInterstitial, TWMTAMediaInterstitialViewDelegate> { TWMTAMediaInterstitialView *adView; } @end @implementation TWMTAMediaCustomInterstitialView @synthesize delegate; - (void)requestInterstitialAdWithParameter:(NSString *)serverParameter label:(NSString *)serverLabel request:(GADCustomEventRequest *)customEventRequest { CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, [UIScreen mainScreen].applicationFrame.size.height); adView = [[TWMTAMediaInterstitialView alloc] initWithFrame:frame slotId:serverParameter developerID:@"" gpsEnabled:YES testMode:NO]; adView.delegate = self; [adView receiveAd]; } - (void)presentFromRootViewController:(UIViewController *)rootViewController { CGRect frame = CGRectMake(0, 0, 0, 0); frame.size.width = [UIScreen mainScreen].applicationFrame.size.width; frame.size.height = [UIScreen mainScreen].applicationFrame.size.height; adView.frame = frame; [rootViewController.view addSubview:adView]; [rootViewController.view bringSubviewToFront:adView]; } - (void)interstitialViewWillLoadAd:(TWMTAMediaInterstitialView *)view { NSLog(@"%@ interstitialViewWillLoadAd", view); [self.delegate customEventInterstitial:self didReceiveAd:view]; } - (void)interstitialViewDidLoadAd:(TWMTAMediaInterstitialView *)view { NSLog(@"%@ interstitialViewDidLoadAd", view); [self.delegate customEventInterstitial:self didReceiveAd:view]; } - (void)interstitialView:(TWMTAMediaInterstitialView *)view didFailToReceiveAdWithError:(NSError *)error { NSLog(@"%@ interstitialViewdidFailToReceiveAdWithError:%@", view, error.description); [self.delegate customEventInterstitial:self didFailAd:error]; } - (BOOL)interstitialViewActionShouldBegin:(TWMTAMediaInterstitialView *)view willLeaveApplication:(BOOL)willLeave { NSLog(@"%@ interstitialViewwillLeaveApplication:%i", view, willLeave); [self.delegate customEventInterstitialWillLeaveApplication:self]; return YES; } - (void)interstitialViewWillDisappear:(TWMTAMediaInterstitialView *)view { NSLog(@"%@ interstitialViewWillDisappear", view); [self.delegate customEventInterstitialWillDismiss:self]; } - (void)interstitialViewDidDisappear:(TWMTAMediaInterstitialView *)view { NSLog(@"%@ interstitialViewDidDisappear", view); [self.delegate customEventInterstitialDidDismiss:self]; } @end