ATNativeAdWrapper.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. //
  2. // ATNativeAdWrapper.m
  3. // UnityContainer
  4. //
  5. // Created by Martin Lau on 27/07/2018.
  6. // Copyright © 2018 Martin Lau. All rights reserved.
  7. //
  8. #import "ATNativeAdWrapper.h"
  9. #import "ATUnityUtilities.h"
  10. #import <Foundation/Foundation.h>
  11. #import <UIKit/UIKit.h>
  12. #import <AnyThinkNative/ATAdManager+Native.h>
  13. #import <AnyThinkNative/ATNativeAdConfiguration.h>
  14. #import <AnyThinkNative/ATNativeADView.h>
  15. #import "ATAutolayoutCategories.h"
  16. #import "ATUnityManager.h"
  17. #import "ATNativeSelfRenderView.h"
  18. #define kNavigationBarHeight ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown ? ([[UIApplication sharedApplication]statusBarFrame].size.height + 44) : ([[UIApplication sharedApplication]statusBarFrame].size.height - 4))
  19. #define kScreenW ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown ? UIScreen.mainScreen.bounds.size.width : UIScreen.mainScreen.bounds.size.height)
  20. NSString *const kParsedPropertiesFrameKey = @"frame";
  21. NSString *const kParsedPropertiesBackgroundColorKey = @"background_color";
  22. NSString *const kParsedPropertiesTextColorKey = @"text_color";
  23. NSString *const kParsedPropertiesTextSizeKey = @"text_size";
  24. NSString *const kNativeAssetAdvertiser = @"advertiser_label";
  25. NSString *const kNativeAssetText = @"text";
  26. NSString *const kNativeAssetTitle = @"title";
  27. NSString *const kNativeAssetCta = @"cta";
  28. NSString *const kNativeAssetRating = @"rating";
  29. NSString *const kNativeAssetIcon = @"icon";
  30. NSString *const kNativeAssetMainImage = @"main_image";
  31. NSString *const kNativeAssetSponsorImage = @"sponsor_image";
  32. NSString *const kNativeAssetDislike = @"dislike_button";
  33. NSString *const kNativeAssetMedia = @"media";
  34. NSString *kATAdLoadingExtraNativeAdSizeKey = @"native_ad_size";
  35. NSString *kATNativeAdSizeUsesPixelFlagKey = @"uses_pixel";
  36. NSDictionary* at_parseUnityProperties(NSDictionary *properties) {
  37. NSMutableDictionary *result = NSMutableDictionary.dictionary;
  38. CGFloat scale = [properties[@"usesPixel"] boolValue] ? [UIScreen mainScreen].nativeScale : 1.0f;
  39. result[kParsedPropertiesFrameKey] = [NSString stringWithFormat:@"{{%@, %@}, {%@, %@}}", @([properties[@"x"] doubleValue] / scale), @([properties[@"y"] doubleValue] / scale), @([properties[@"width"] doubleValue] / scale), @([properties[@"height"] doubleValue] / scale)];
  40. result[kParsedPropertiesBackgroundColorKey] = properties[@"backgroundColor"];
  41. result[kParsedPropertiesTextColorKey] = properties[@"textColor"];
  42. result[kParsedPropertiesTextSizeKey] = properties[@"textSize"];
  43. return result;
  44. }
  45. NSDictionary* at_parseUnityMetrics(NSDictionary* metrics) {
  46. NSMutableDictionary *result = NSMutableDictionary.dictionary;
  47. NSDictionary *keysMap = @{@"appIcon":kNativeAssetIcon, @"mainImage":kNativeAssetMainImage, @"title":kNativeAssetTitle, @"desc":kNativeAssetText, @"adLogo":kNativeAssetSponsorImage, @"cta":kNativeAssetCta, @"dislike":kNativeAssetDislike};
  48. [keysMap enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { result[keysMap[key]] = at_parseUnityProperties(metrics[key]); }];
  49. return result;
  50. }
  51. #define CS_ATNativeAdWrapper "ATNativeAdWrapper"
  52. NSString *const kATNativeAdAdaptiveHeightKey = @"AdaptiveHeight";
  53. @interface ATNativeAdWrapper()
  54. @property(nonatomic, strong) ATNativeSelfRenderView *nativeSelfRenderView;
  55. @property(nonatomic, strong) ATNativeADView *adView;
  56. @property(nonatomic, readonly) NSMutableDictionary<NSString*, UIView*> *viewsStorage;
  57. @end
  58. @implementation ATNativeAdWrapper
  59. +(instancetype)sharedInstance {
  60. static ATNativeAdWrapper *sharedInstance = nil;
  61. static dispatch_once_t onceToken;
  62. dispatch_once(&onceToken, ^{
  63. sharedInstance = [[ATNativeAdWrapper alloc] init];
  64. });
  65. return sharedInstance;
  66. }
  67. -(instancetype) init {
  68. self = [super init];
  69. if (self != nil) {
  70. _viewsStorage = [NSMutableDictionary<NSString*, UIView*> dictionary];
  71. }
  72. return self;
  73. }
  74. UIEdgeInsets SafeAreaInsets_ATUnityNative() {
  75. return ([[UIApplication sharedApplication].keyWindow respondsToSelector:@selector(safeAreaInsets)] ? [UIApplication sharedApplication].keyWindow.safeAreaInsets : UIEdgeInsetsZero);
  76. }
  77. - (id)selWrapperClassWithDict:(NSDictionary *)dict callback:(void(*)(const char*, const char*))callback {
  78. NSString *selector = dict[@"selector"];
  79. NSArray<NSString*>* arguments = dict[@"arguments"];
  80. NSString *firstObject = @"";
  81. NSString *secondObject = @"";
  82. NSString *lastObject = @"";
  83. if (![ATUnityUtilities isEmpty:arguments]) {
  84. for (int i = 0; i < arguments.count; i++) {
  85. if (i == 0) { firstObject = arguments[i]; }
  86. else if (i == 1) { secondObject = arguments[i]; }
  87. else { lastObject = arguments[i]; }
  88. }
  89. }
  90. if ([selector isEqualToString:@"loadNativeAdWithPlacementID:customDataJSONString:callback:"]) {
  91. [self loadNativeAdWithPlacementID:firstObject customDataJSONString:secondObject callback:callback];
  92. } else if ([selector isEqualToString:@"isNativeAdReadyForPlacementID:"]) {
  93. return [NSNumber numberWithBool:[self isNativeAdReadyForPlacementID:firstObject]];
  94. } else if ([selector isEqualToString:@"showNativeAdWithPlacementID:metricsJSONString:extraJsonString:"]) {
  95. [self showNativeAdWithPlacementID:firstObject metricsJSONString:secondObject extraJsonString:lastObject];
  96. } else if ([selector isEqualToString:@"removeNativeAdViewWithPlacementID:"]) {
  97. [self removeNativeAdViewWithPlacementID:firstObject];
  98. } else if ([selector isEqualToString:@"checkAdStatus:"]) {
  99. return [self checkAdStatus:firstObject];
  100. } else if ([selector isEqualToString:@"clearCache"]) {
  101. [self clearCache];
  102. } else if ([selector isEqualToString:@"getValidAdCaches:"]) {
  103. return [self getValidAdCaches:firstObject];
  104. }else if ([selector isEqualToString:@"entryScenarioWithPlacementID:scenarioID:"]) {
  105. [self entryScenarioWithPlacementID:firstObject scenarioID:secondObject];
  106. }
  107. return nil;
  108. }
  109. -(void) loadNativeAdWithPlacementID:(NSString*)placementID customDataJSONString:(NSString*)customDataJSONString callback:(void(*)(const char*, const char *))callback {
  110. [self setCallBack:callback forKey:placementID];
  111. NSMutableDictionary *extra = [NSMutableDictionary dictionaryWithDictionary:@{kATExtraInfoNativeAdTypeKey:@(ATGDTNativeAdTypeSelfRendering), kATExtraNativeImageSizeKey:kATExtraNativeImageSize690_388}];
  112. if ([customDataJSONString isKindOfClass:[NSString class]] && [customDataJSONString length] > 0) {
  113. NSDictionary *extraDict = [NSJSONSerialization JSONObjectWithData:[customDataJSONString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
  114. NSLog(@"extraDict = %@", extraDict);
  115. CGFloat scale = [extraDict[kATNativeAdSizeUsesPixelFlagKey] boolValue] ? [UIScreen mainScreen].nativeScale : 1.0f;
  116. if ([extraDict[kATAdLoadingExtraNativeAdSizeKey] isKindOfClass:[NSString class]] && [[extraDict[kATAdLoadingExtraNativeAdSizeKey] componentsSeparatedByString:@"x"] count] == 2) {
  117. NSArray<NSString*>* com = [extraDict[kATAdLoadingExtraNativeAdSizeKey] componentsSeparatedByString:@"x"];
  118. extra[kATExtraInfoNativeAdSizeKey] = [NSValue valueWithCGSize:CGSizeMake([com[0] doubleValue] / scale, [com[1] doubleValue] / scale)];
  119. }
  120. }
  121. NSLog(@"extra = %@", extra);
  122. [[ATAdManager sharedManager] loadADWithPlacementID:placementID extra:extra delegate:self];
  123. }
  124. -(BOOL) isNativeAdReadyForPlacementID:(NSString*)placementID {
  125. return [[ATAdManager sharedManager] nativeAdReadyForPlacementID:placementID];
  126. }
  127. -(NSString*) checkAdStatus:(NSString *)placementID {
  128. ATCheckLoadModel *checkLoadModel = [[ATAdManager sharedManager] checkNativeLoadStatusForPlacementID:placementID];
  129. NSMutableDictionary *statusDict = [NSMutableDictionary dictionary];
  130. statusDict[@"isLoading"] = @(checkLoadModel.isLoading);
  131. statusDict[@"isReady"] = @(checkLoadModel.isReady);
  132. statusDict[@"adInfo"] = checkLoadModel.adOfferInfo;
  133. NSLog(@"ATNativeAdWrapper::statusDict = %@", statusDict);
  134. return statusDict.jsonFilterString;
  135. }
  136. - (void)entryScenarioWithPlacementID:(NSString *)placementID scenarioID:(NSString *)scenarioID{
  137. [[ATAdManager sharedManager] entryNativeScenarioWithPlacementID:placementID scene:scenarioID];
  138. }
  139. -(NSString*) getValidAdCaches:(NSString *)placementID {
  140. NSArray *array = [[ATAdManager sharedManager] getNativeValidAdsForPlacementID:placementID];
  141. NSLog(@"ATNativeAdWrapper::array = %@", array);
  142. return array.jsonFilterString;
  143. }
  144. -(void) showNativeAdWithPlacementID:(NSString*)placementID metricsJSONString:(NSString*)metricsJSONString extraJsonString:(NSString*)extraJsonString {
  145. if (self.adView) {
  146. [self.adView removeFromSuperview];
  147. self.adView = nil;
  148. }
  149. if ([self isNativeAdReadyForPlacementID:placementID]) {
  150. NSDictionary *metrics = [NSJSONSerialization JSONObjectWithData:[metricsJSONString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
  151. NSDictionary *extraDict = ([extraJsonString isKindOfClass:[NSString class]] && [extraJsonString dataUsingEncoding:NSUTF8StringEncoding] != nil) ? [NSJSONSerialization JSONObjectWithData:[extraJsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil] : nil;
  152. NSDictionary *parsedMetrics = at_parseUnityMetrics(metrics);
  153. NSLog(@"metrics = %@, parsedMetrics = %@", metrics, parsedMetrics);
  154. NSLog(@"ATNativeAdWrapper::extraDict:%@",extraDict);
  155. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  156. [button addTarget:self action:@selector(noop) forControlEvents:UIControlEventTouchUpInside];
  157. button.frame = CGRectFromString(at_parseUnityProperties(metrics[@"parent"])[kParsedPropertiesFrameKey]);
  158. CGRect adViewFrame = CGRectFromString(at_parseUnityProperties(metrics[@"parent"])[kParsedPropertiesFrameKey]);
  159. CGRect mediaViewFrame = CGRectFromString(parsedMetrics[kNativeAssetMainImage][kParsedPropertiesFrameKey]);
  160. CGRect logoFrame = CGRectFromString(parsedMetrics[kNativeAssetSponsorImage][kParsedPropertiesFrameKey]);
  161. ATNativeADConfiguration *configuration = [ATNativeADConfiguration new];
  162. configuration.ADFrame = CGRectMake(0, 0, CGRectGetWidth(adViewFrame), CGRectGetHeight(adViewFrame));
  163. configuration.mediaViewFrame = mediaViewFrame;
  164. configuration.logoViewFrame = logoFrame;
  165. configuration.delegate = self;
  166. if (extraDict[kATNativeAdAdaptiveHeightKey] != nil) {
  167. configuration.sizeToFit = [extraDict[kATNativeAdAdaptiveHeightKey] boolValue];
  168. }
  169. configuration.rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
  170. configuration.context = @{
  171. kATNativeAdConfigurationContextAdOptionsViewFrameKey:[NSValue valueWithCGRect:CGRectMake(CGRectGetWidth([UIScreen mainScreen].bounds) - 43.0f, .0f, 43.0f, 18.0f)],
  172. kATNativeAdConfigurationContextAdLogoViewFrameKey:[NSValue valueWithCGRect:CGRectMake(.0f, .0f, 54.0f, 18.0f)],
  173. kATNativeAdConfigurationContextNetworkLogoViewFrameKey:[NSValue valueWithCGRect:CGRectMake(CGRectGetWidth(configuration.ADFrame) - 54.0f, CGRectGetHeight(configuration.ADFrame) - 18.0f, 54.0f, 18.0f)]
  174. };
  175. ATNativeAdOffer *offer = [[ATAdManager sharedManager] getNativeAdOfferWithPlacementID:placementID scene:extraDict[kATUnityUtilitiesAdShowingExtraScenarioKey]];
  176. ATNativeSelfRenderView *selfRenderView = [self getSelfRenderViewOffer:offer withMetrics:parsedMetrics];
  177. selfRenderView.backgroundColor = [UIColor colorWithHexString:parsedMetrics[kNativeAssetMainImage][@"background_color"]];
  178. ATNativeADView *adview = [self getNativeADView:configuration offer:offer selfRenderView:selfRenderView withPlacementId:placementID];
  179. [self prepareWithNativePrepareInfo:selfRenderView nativeADView:adview];
  180. [offer rendererWithConfiguration:configuration selfRenderView:selfRenderView nativeADView:adview];
  181. // 是否隐藏内部渲染logoView
  182. if (logoFrame.size.width == 0 || logoFrame.size.height == 0) {
  183. adview.logoImageView.hidden = YES;
  184. }
  185. adview.ctaLabel.hidden = [adview.nativeAd.ctaText length] == 0;
  186. if (adview != nil) {
  187. [self removeNativeAdViewWithPlacementID:placementID];
  188. _viewsStorage[placementID] = button;
  189. [button addSubview:adview];
  190. [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:button];
  191. NSString *position = extraDict[@"Position"];
  192. CGSize totalSize = [UIApplication sharedApplication].keyWindow.rootViewController.view.bounds.size;
  193. UIEdgeInsets safeAreaInsets = SafeAreaInsets_ATUnityNative();
  194. if ([@"Top" isEqualToString:position]) {
  195. button.frame = CGRectMake((totalSize.width - CGRectGetWidth(adview.bounds)) / 2.0f, safeAreaInsets.top , CGRectGetWidth(adview.bounds), CGRectGetHeight(adview.bounds));
  196. } else if ([@"Bottom" isEqualToString:position]) {
  197. button.frame = CGRectMake((totalSize.width - CGRectGetWidth(adview.bounds)) / 2.0f, totalSize.height - safeAreaInsets.bottom - CGRectGetHeight(adview.bounds) , CGRectGetWidth(adview.bounds), CGRectGetHeight(adview.bounds));
  198. } else {
  199. button.frame = CGRectFromString(at_parseUnityProperties(metrics[@"parent"])[kParsedPropertiesFrameKey]);
  200. }
  201. NSMutableDictionary *contextStorage = [NSMutableDictionary dictionary];
  202. [contextStorage setValue:button forKey:@"button"];
  203. [contextStorage setValue:position forKey:@"position"];
  204. [adview addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:(void*)CFBridgingRetain(contextStorage)];
  205. }
  206. }
  207. }
  208. - (void)prepareWithNativePrepareInfo:(ATNativeSelfRenderView *)selfRenderView nativeADView:(ATNativeADView *)nativeADView{
  209. ATNativePrepareInfo *info = [ATNativePrepareInfo loadPrepareInfo:^(ATNativePrepareInfo * _Nonnull prepareInfo) {
  210. prepareInfo.textLabel = selfRenderView.textLabel;
  211. prepareInfo.advertiserLabel = selfRenderView.advertiserLabel;
  212. prepareInfo.titleLabel = selfRenderView.titleLabel;
  213. prepareInfo.ratingLabel = selfRenderView.ratingLabel;
  214. prepareInfo.iconImageView = selfRenderView.iconImageView;
  215. prepareInfo.mainImageView = selfRenderView.mainImageView;
  216. prepareInfo.dislikeButton = selfRenderView.dislikeButton;
  217. prepareInfo.ctaLabel = selfRenderView.ctaLabel;
  218. prepareInfo.mediaView = selfRenderView.mediaView;
  219. }];
  220. [nativeADView prepareWithNativePrepareInfo:info];
  221. [nativeADView addSubview:selfRenderView];
  222. selfRenderView.frame = CGRectMake(0, 0, CGRectGetWidth(nativeADView.frame), CGRectGetHeight(nativeADView.frame));
  223. }
  224. - (ATNativeSelfRenderView *)getSelfRenderViewOffer:(ATNativeAdOffer *)offer withMetrics:(NSDictionary*)metrics{
  225. ATNativeSelfRenderView *selfRenderView = [[ATNativeSelfRenderView alloc]initWithOffer:offer];
  226. self.nativeSelfRenderView = selfRenderView;
  227. [selfRenderView configureMetrics:metrics];
  228. return selfRenderView;
  229. }
  230. - (ATNativeADView *)getNativeADView:(ATNativeADConfiguration *)config offer:(ATNativeAdOffer *)offer selfRenderView:(ATNativeSelfRenderView *)selfRenderView withPlacementId:(NSString*)placementID{
  231. ATNativeADView *nativeADView = [[ATNativeADView alloc]initWithConfiguration:config currentOffer:offer placementID:placementID];
  232. UIView *mediaView = [nativeADView getMediaView];
  233. NSMutableArray *array = [@[selfRenderView.iconImageView,selfRenderView.titleLabel,selfRenderView.textLabel,selfRenderView.ctaLabel,selfRenderView.mainImageView] mutableCopy];
  234. if (mediaView && offer.nativeAd.isVideoContents) {
  235. [array addObject:mediaView];
  236. selfRenderView.mediaView = mediaView;
  237. [selfRenderView addSubview:mediaView];
  238. }
  239. [nativeADView registerClickableViewArray:array];
  240. self.adView = nativeADView;
  241. return nativeADView;
  242. }
  243. -(void) noop {
  244. }
  245. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  246. if ([keyPath isEqualToString:@"frame"]) {
  247. CGRect frame = [change[@"new"] CGRectValue];
  248. NSDictionary *contextDict = (__bridge NSDictionary*)context;
  249. CGSize totalSize = [UIApplication sharedApplication].keyWindow.rootViewController.view.bounds.size;
  250. UIEdgeInsets safeAreaInsets = SafeAreaInsets_ATUnityNative();
  251. NSString *position = contextDict[@"position"];
  252. UIButton *button = contextDict[@"button"];
  253. CGRect buttonFrame = button.frame;
  254. buttonFrame.size.height = frame.size.height;
  255. if ([position isEqualToString:@"Bottom"]) {
  256. buttonFrame.origin.y = totalSize.height - safeAreaInsets.bottom - frame.size.height;
  257. }
  258. button.frame = buttonFrame;
  259. [object removeObserver:self forKeyPath:@"frame"];
  260. CFBridgingRelease(context);
  261. }
  262. }
  263. -(void) removeNativeAdViewWithPlacementID:(NSString*)placementID {
  264. if ([_viewsStorage.allKeys containsObject:placementID]) {
  265. [_viewsStorage[placementID] removeFromSuperview];
  266. }
  267. }
  268. -(void) clearCache {
  269. }
  270. -(NSString*) scriptWrapperClass {
  271. return @"ATNativeAdWrapper";
  272. }
  273. #pragma mark - delegate
  274. -(void) didFinishLoadingADWithPlacementID:(NSString *)placementID {
  275. [self invokeCallback:@"OnNativeAdLoaded" placementID:placementID error:nil extra:nil];
  276. }
  277. -(void) didFailToLoadADWithPlacementID:(NSString*)placementID error:(NSError*)error {
  278. [self invokeCallback:@"OnNativeAdLoadingFailure" placementID:placementID error:error extra:nil];
  279. }
  280. // ad
  281. - (void)didStartLoadingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra{
  282. [self invokeCallback:@"startLoadingADSource" placementID:placementID error:nil extra:extra];
  283. }
  284. - (void)didFinishLoadingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra{
  285. [self invokeCallback:@"finishLoadingADSource" placementID:placementID error:nil extra:extra];
  286. }
  287. - (void)didFailToLoadADSourceWithPlacementID:(NSString*)placementID extra:(NSDictionary*)extra error:(NSError*)error{
  288. [self invokeCallback:@"failToLoadADSource" placementID:placementID error:error extra:extra];
  289. }
  290. // bidding
  291. - (void)didStartBiddingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra{
  292. [self invokeCallback:@"startBiddingADSource" placementID:placementID error:nil extra:extra];
  293. }
  294. - (void)didFinishBiddingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra{
  295. [self invokeCallback:@"finishBiddingADSource" placementID:placementID error:nil extra:extra];
  296. }
  297. - (void)didFailBiddingADSourceWithPlacementID:(NSString*)placementID extra:(NSDictionary*)extra error:(NSError*)error{
  298. [self invokeCallback:@"failBiddingADSource" placementID:placementID error:error extra:extra];
  299. }
  300. -(void) didShowNativeAdInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra {
  301. [self invokeCallback:@"OnNaitveAdShow" placementID:placementID error:nil extra:extra];
  302. }
  303. -(void) didClickNativeAdInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra {
  304. //Drop ad view
  305. [self invokeCallback:@"OnNativeAdClick" placementID:placementID error:nil extra:extra];
  306. }
  307. -(void) didTapCloseButtonInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra {
  308. [self invokeCallback:@"OnNativeAdCloseButtonClick" placementID:placementID error:nil extra:extra];
  309. [self.adView removeFromSuperview];
  310. }
  311. -(void) didStartPlayingVideoInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra {
  312. //Drop ad view
  313. [self invokeCallback:@"OnNativeAdVideoStart" placementID:placementID error:nil extra:extra];
  314. }
  315. -(void) didEndPlayingVideoInAdView:(ATNativeADView*)adView placementID:(NSString*)placementID extra:(NSDictionary *)extra {
  316. //Drop ad view
  317. [self invokeCallback:@"OnNativeAdVideoEnd" placementID:placementID error:nil extra:extra];
  318. }
  319. @end