title: Show AdMob Native Ads with MoPub (iOS)
body: <p>I am integrating MoPub SDK to mediate ADs from the Google AdMob network. I can get the AD to show after implementing my own customEvent and Adapter, but i can't get the AD to handle click events on its own. As in when I click on the AdMob native AD, it won't direct me anywhere. When using Facebook and Flurry's CustomEvent and Adapter, clicks are handled automatically. Anyone have any experience on this subject? </p>
  
  <p>Thanks in Advance. Code below:</p>
  
  <p>MPGoogleAdMobCustomEvent</p>
  
  <pre><code>@interface MPGoogleAdMobCustomEvent()
  @property(nonatomic, strong)GADAdLoader *loader;
  @end
  
  @implementation MPGoogleAdMobCustomEvent
  
  - (void)requestAdWithCustomEventInfo:(NSDictionary *)info
  {
      MPLogInfo(@"MOPUB: requesting AdMob Native Ad");
  
      NSString *adUnitID = [info objectForKey:@"adUnitID"];
  
      if (!adUnitID) {
  
          [self.delegate nativeCustomEvent:self didFailToLoadAdWithError:MPNativeAdNSErrorForInvalidAdServerResponse(@"MOPUB: No AdUnitID from GoogleAdMob")];
  
          return;
      }
  
      self.loader = [[GADAdLoader alloc] initWithAdUnitID:adUnitID rootViewController:nil  adTypes:@[kGADAdLoaderAdTypeNativeContent] options:nil];
      self.loader.delegate = self;
      GADRequest *request = [GADRequest request];
  
  #if (TARGET_OS_SIMULATOR)
  
      request.testDevices = @[ kGADSimulatorID ];
  
  #endif
  
      CLLocation *location = [[CLLocationManager alloc] init].location;
      if (location) {
          [request setLocationWithLatitude:location.coordinate.latitude
                                 longitude:location.coordinate.longitude
                                  accuracy:location.horizontalAccuracy];
      }
      request.requestAgent = @"MoPub";
      [self.loader loadRequest:request];
  }
  
  - (void)adLoader:(GADAdLoader *)adLoader didReceiveNativeContentAd:(GADNativeContentAd *)nativeContentAd
  {
      MPLogDebug(@"MOPUB: Did receive nativeAd");
  
      MPGoogleAdMobNativeAdAdapter *adapter = [[MPGoogleAdMobNativeAdAdapter alloc] initWithGADNativeContentAd:nativeContentAd];
      adapter.url = nativeContentAd.advertiser;
      MPNativeAd *interfaceAd = [[MPNativeAd alloc] initWithAdAdapter:adapter];
  
      NSMutableArray *imageArray = [NSMutableArray array];
  
      for (GADNativeAdImage *images in nativeContentAd.images) {
  
          [imageArray addObject:images.imageURL];
  
      }
  
  
      [super precacheImagesWithURLs:imageArray completionBlock:^(NSArray *errors) {
  
          if ([errors count]) {
              [self.delegate nativeCustomEvent:self didFailToLoadAdWithError:errors[0]];
          } else {
              [self.delegate nativeCustomEvent:self didLoadAd:interfaceAd];
          }
  
      }];
  }
  
  - (void)adLoader:(GADAdLoader *)adLoader didFailToReceiveAdWithError:(GADRequestError *)error
  {
      MPLogDebug(@"MOPUB: AdMob ad failed to load with error (customEvent): %@", error.description);
      [self.delegate nativeCustomEvent:self didFailToLoadAdWithError:error];
  }
  
  @end
  </code></pre>
  
  <p>MPGoogleAdMobNativeAdAdapter</p>
  
  <pre><code>@interface MPGoogleAdMobNativeAdAdapter()&lt;GADNativeAdDelegate&gt;
  @property(nonatomic, strong)NSDictionary *properties;
  @end
  
  @implementation MPGoogleAdMobNativeAdAdapter
  
  - (instancetype)initWithGADNativeContentAd:(GADNativeContentAd *)contentAD
  {
      self = [super init];
      if (self) {
          self.contentAd = contentAD;
          self.contentAd.delegate = self;
          self.properties = [self convertAssetsToProperties:contentAD];
      }
      return self;
  }
  
  - (NSDictionary *)convertAssetsToProperties:(GADNativeContentAd *)adNative
  {
      self.contentAd = adNative;
      NSMutableDictionary * dictionary = [NSMutableDictionary dictionary];
      if (adNative.headline) {
          dictionary[kAdTitleKey] = adNative.headline;
      }
      if (adNative.body) {
          dictionary[kAdTextKey] = adNative.body;
      }
      if (adNative.images[0]) {
          dictionary[kAdMainImageKey] = ((GADNativeAdImage *)adNative.images[0]).imageURL.absoluteString;
      }
      if (adNative.callToAction) {
          dictionary[kAdCTATextKey] = adNative.callToAction;
      }
      return [dictionary copy];
  }
  
  #pragma mark MPNativeAdAdapter
  - (NSTimeInterval)requiredSecondsForImpression
  {
      return 0.0;
  }
  
  - (NSURL *)defaultActionURL
  {
      return nil;
  }
  
  - (BOOL)enableThirdPartyClickTracking
  {
      return YES;
  }
  
  
  - (void)willAttachToView:(UIView *)view
  {
      self.contentAd.rootViewController = [self.delegate viewControllerForPresentingModalView];
  }
  
  - (void)didDetachFromView:(UIView *)view
  {
      self.contentAd.rootViewController = nil;
  }
  
  #pragma mark GADNativeAdDelegate
  
  - (void)nativeAdWillPresentScreen:(GADNativeAd *)nativeAd
  {
      if ([self.delegate respondsToSelector:@selector(nativeAdWillPresentModalForAdapter:)]) {
          [self.delegate nativeAdWillPresentModalForAdapter:self];
      }
  }
  
  - (void)nativeAdDidDismissScreen:(GADNativeAd *)nativeAd
  {
      if ([self.delegate respondsToSelector:@selector(nativeAdDidDismissModalForAdapter:)]) {
          [self.delegate nativeAdDidDismissModalForAdapter:self];
      }
  }
  
  - (void)nativeAdWillLeaveApplication:(GADNativeAd *)nativeAd
  {
      if ([self.delegate respondsToSelector:@selector(nativeAdWillLeaveApplicationFromAdapter:)]) {
          [self.delegate nativeAdWillLeaveApplicationFromAdapter:self];
      }
  }
  
  @end
  
  
  
  
  `
  </code></pre>