IOS Google Native ad not clickable

Below is my code. When I click on an ad presented in a UITableViewCell didSelectRowAtIndexPath

, it gets called and the ad doesn't open in the browser.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"NewsCell";
  UITableViewCell  *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
            if ([[_arrAllNewsListing objectAtIndex:indexPath.row] isKindOfClass:[GADNativeContentAd class]]){
                NSMutableDictionary *dataDict = _arrAllNewsListing[indexPath.row];

                __block NativeAddCell *nativCell = [[NativeAddCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"NativeNewsContentAdCell" cellType:1];
                GADNativeContentAd *ads = (GADNativeContentAd *)dataDict;
                if(IsValidString(ads.headline)){
                    [nativCell.lblHeadline setText:ads.headline];
                    [nativCell.gadInstallView setHeadlineView:nativCell.lblHeadline];
                }

                if(IsValidString(ads.body)){
                    [nativCell.lblBodyText setText:ads.body];
                    [nativCell.gadView setBodyView:nativCell.lblBodyText];
                }

                if(IsArrayWithItems(ads.images) && [ads.images count] > 0){
                    __weak NativeAddCell *weakcell = nativCell;
                    [nativCell.imgView setImage:nil];
                    GADNativeAdImage* imageObj = (GADNativeAdImage*)ads.images[0];
                    if(imageObj != nil){
                        if(imageObj.image != nil){
                            [nativCell.imgView setImage:imageObj.image];
                        }
                        else if(imageObj.imageURL != nil){
                            [nativCell.imgView sd_setImageWithURL:imageObj.imageURL completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                                if (image) {
                                    weakcell.imgView.image = image;
                                }
                                if (error != nil ) {
                                    [weakcell.imageView setImage:nil];
                                }
                            }];
                        }
                        [nativCell.gadView setImageView:nativCell.imageView];
                    }
                }

                if(IsValidString(ads.callToAction))
                    [nativCell.lblCallToAction setText:ads.callToAction];

                [nativCell.gadView setCallToActionView:nativCell.gadView];
                [nativCell.gadView setNativeContentAd:ads];

                nativCell.gadView.userInteractionEnabled = NO;
                return nativCell;
            }
            else
            {
                if([[[_arrAllNewsListing objectAtIndex:indexPath.row] valueForKey:@"NATIVE_AD_SPOT"] isEqualToString:@"YES"])
                {

                    NSString *adunit = @"/XXXXX/example/native-backfill";
                    self.nativeAdLoader = [[GADAdLoader alloc]
                                           initWithAdUnitID:adunit
                                           rootViewController:self
                                           adTypes:@[kGADAdLoaderAdTypeNativeContent]
                                           options:nil];
                    self.nativeAdLoader.delegate = self;
                    [self.nativeAdLoader loadRequest:[GADRequest request]];
                    [[_arrAllNewsListing objectAtIndex:indexPath.row] setValue:self.nativeAdLoader forKey:@"AD_OBJECT"];
                }
            }
    return cell;
}

      

The ad is loading as expected, but the clicks event is not working. Couldn't find any solutions in google documentation and code examples.

+3


source to share


1 answer


If you are not using Google's .xib file, you must call their method registerAdView()

on the class GADNativeContentAd

:

- (void)registerAdView:(UIView *)adView
   clickableAssetViews:(NSDictionary<GADNativeContentAdAssetID, UIView *> *)clickableAssetViews
   nonclickableAssetViews: (NSDictionary<GADNativeContentAdAssetID, UIView *> *)nonclickableAssetViews;

      



Please see my Swift example in an answer to a similar question:

Admob Native Advanced is not available for download

0


source







All Articles