3

以下是我的代码。当我单击 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;
}

广告正在正确加载,但点击事件不起作用。在谷歌文档和示例代码上找不到任何解决方案。

4

1 回答 1

1

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

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

请在回答类似问题时查看我的 Swift 示例:

Admob Native Advanced 不可点击

于 2018-03-15T19:09:12.737 回答