「Mopub Mediation Banner」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser |
imported>Wikiuser |
||
行 9: | 行 9: | ||
[[MoPub Mediation Setting|回MoPub教學]] | [[MoPub Mediation Setting|回MoPub教學]] | ||
== | == TAMediaCustomBannerEvent == | ||
'''// | '''// TAMediaCustomBannerEvent.h''' | ||
//匯入TADBannerVIew | //匯入TADBannerVIew | ||
#import "MPBannerCustomEvent.h" | #import "MPBannerCustomEvent.h" | ||
#import "TADBannerView.h" | #import "TADBannerView.h" | ||
@interface | @interface TAMediaCustomBannerEvent : MPBannerCustomEvent<TADBannerViewDelegate> | ||
@property (nonatomic, strong) TADBannerView *bannerView; | @property (nonatomic, strong) TADBannerView *bannerView; | ||
@end | @end | ||
#import " | #import "TAMediaCustomBannerEvent.h" | ||
@implementation | @implementation TAMediaCustomBannerEvent | ||
- (void)requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info { | - (void)requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info { |
於 2017年7月14日 (五) 10:47 的修訂
依照Mopub設定教學設定後,開始實做Custom event
官方教學:連結
1.先建立一class繼承MPBannerCustomEvent,class名稱必須與Mopub設定內一樣
2.加入Tamedia TADBannerView.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 "TADBannerView.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:1988 month:6 day:11]; [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