Mopub Mediation Banner
於 2018年8月21日 (二) 02:49 由 imported>Wikiuser 所做的修訂 (→TAMediaCustomBannerEvent)
依照Mopub設定教學設定後,開始實做Custom event
官方教學:連結
1.先建立一class繼承MPBannerCustomEvent,class名稱必須與Mopub設定內一樣
2.加入#import <TAMediaAdsFramework/TAMediaAdsFramework.h>
3.複寫- (void)requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info
以及在此method內用TADBannerView呼叫廣告
4.在TADBannerView delegate內呼叫MPBannerCustomEvent delegate執行相對應的method
可參考以下代碼
TAMediaCustomBannerEvent
// TAMediaCustomBannerEvent.h //匯入TADBannerVIew #import "MPBannerCustomEvent.h" #import <TAMediaAdsFramework/TAMediaAdsFramework.h> @interface TAMediaCustomBannerEvent : MPBannerCustomEvent<TADBannerViewDelegate> @property (nonatomic, strong) TADBannerView *bannerView; @end
#import "TAMediaCustomBannerEvent.h" @implementation TAMediaCustomBannerEvent - (void)requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info { TADRequest *request = [TADRequest request]; request.testing = NO; request.gender = kTADGenderUnknown; [request setBirthdayWithYear:xxxx month:xx day:xx]; [request setLocationWithLatitude:25.033534 longitude:121.534791 accuracy:1]; if (!self.bannerView) { self.bannerView = [[TADBannerView alloc] initWithAdSize:TADAdSizeFromCGSize(size)]; } self.bannerView.delegate = self; self.bannerView.turnOnMicrophone = NO; NSString *bannerId = info[@"BannerId"];//此處BannerId是在Mopub內設定 self.bannerView.adUnitID = bannerId; self.bannerView.rootViewController = [[UIApplication sharedApplication] keyWindow].rootViewController; [self.bannerView loadRequest:request]; } #pragma mark - [Tamedia Banner delegate] - (void)adViewDidReceiveAd:(TADBannerView *)view { if ([self.delegate respondsToSelector:@selector(bannerCustomEvent:didLoadAd:)]) { [self.delegate bannerCustomEvent:self didLoadAd:view]; } } - (void)adView:(TADBannerView *)view didFailToReceiveAdWithError:(TADRequestError *)error { if ([self.delegate respondsToSelector:@selector(bannerCustomEvent:didFailToLoadAdWithError:)]) { [self.delegate bannerCustomEvent:self didFailToLoadAdWithError:error]; } } - (void)adViewWillPresentScreen:(TADBannerView *)adView { } - (void)adViewWillDismissScreen:(TADBannerView *)adView { } - (void)adViewDidDismissScreen:(TADBannerView *)adView { } - (void)adViewWillLeaveApplication:(TADBannerView *)adView { if ([self.delegate respondsToSelector:@selector(bannerCustomEventWillLeaveApplication:)]) { [self.delegate bannerCustomEventWillLeaveApplication:self]; } } - (void)dealloc { if (self.bannerView != nil) { self.bannerView.delegate = nil; self.bannerView = nil; } } @end