Mopub Mediation Native
於 2017年6月7日 (三) 09:12 由 imported>Wikiuser 所做的修訂 (新頁面: 官方教學:[https://github.com/mopub/mopub-ios-sdk/wiki/Custom-Events 連結]<br> *Step1. 1.建立一class實做MPNativeAdAdapter protocol,protocol有兩必須實作property:prop...)
官方教學:連結
- Step1.
1.建立一class實做MPNativeAdAdapter protocol,protocol有兩必須實作property:properties及defaultActionURL,此class是作為Tamedia native ad與MPNativeAd的橋樑
2.建立初始化方法,將Tamedia native ad拿到的dictionary作為參數帶入,將帶入的dictionary與MPNativeAdConstants.h提供的key值建立相對應的dictionary後賦予給prooerties
3.defaultActionURL則為Tamedia拿到的nurl
4.實作displayContentForURL:rootViewController:completion:
當user點擊時觸發
參考以下代碼
CustomNativeAdEventAdapter
#import <Foundation/Foundation.h> #import "MPNativeAdAdapter.h" #import "TADNativeAd.h" @interface CustomNativeAdEventAdapter : NSObject <MPNativeAdAdapter> - (instancetype)initWithTADic:(NSDictionary *)taDic; @property (nonatomic, readonly) NSDictionary *properties; @property (nonatomic, readonly) NSURL *defaultActionURL; @end
#import "CustomNativeAdEventAdapter.h" #import "MPNativeAdConstants.h" @interface CustomNativeAdEventAdapter () @end @implementation CustomNativeAdEventAdapter - (instancetype)initWithTADic:(NSDictionary *)taDic { self = [super init]; NSDictionary *taMeidaDicMapping = @{@"LONGSUBJECT":kAdTitleKey, @"BODY":kAdTextKey, @"ICONSQUARE":kAdIconImageKey, @"IMAGE1280X720":kAdMainImageKey, @"VIDEO":kVASTVideoKey, @"nurl":kDefaultActionURLKey, @"IMAGE960X640":@"IMAGE960X640", @"IMAGE1200X627":@"IMAGE1200X627", @"ICONRECTANGLE":@"ICONRECTANGLE", @"SHORTSUBJECT":@"SHORTSUBJECT", @"IMAGE720X1280":@"IMAGE720X1280", @"IMAGE640X960":@"IMAGE640X960"}; NSMutableDictionary *dic = [NSMutableDictionary new]; for (NSString *key in taDic.allKeys) { [dic setObject:taDic[key] forKey:taMeidaDicMapping[key]]; } _properties = dic; _defaultActionURL = [NSURL URLWithString:taDic[@"nurl"]]; return self; } - (void)displayContentForURL:(NSURL *)URL rootViewController:(UIViewController *)controller { [[UIApplication sharedApplication] openURL:URL]; } @end