iOS Google原生广告无法点击

时间:2017-06-06 12:28:46

标签: ios objective-c click tableview native-ads

以下是我的代码。当我点击UITableViewCell上显示的广告didSelectRowAtIndexPath时,系统会调用此广告,并且广告未在浏览器中打开。

- (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;
}

广告正在加载,但点击事件无效。无法在Google文档和示例代码中找到任何解决方案。

1 个答案:

答案 0 :(得分:0)

如果您没有使用Google的.xib文件,则必须在registerAdView()类中调用他们的GADNativeContentAd方法:

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

请在类似问题的答案中查看我的Swift示例:

Admob Native Advanced Not Clickable