首页 文章

Google Admob直播广告未在iOS 11的真实设备上展示

提问于
浏览
4

我在网上和StackOverflow上搜索并发现了与我有相同或类似错误信息的帖子,但没有一个与我有相同的错误 . 它们有不同的条件,即错误信息出现在不同的情况下,或者它们在不同版本的iOS等上 . 我已经尝试了我在网上找到的所有解决方案 .

基本上我使用Admob在我的iOS应用中显示 Banner 广告和插页式广告 . 这些已经在实时应用程序中运行了一年多,它们目前仍在iOS 10设备和早期版本的iOS中运行,没有任何问题 .

但当iOS更新到iOS11时,情况发生了变化 .

测试广告适用于所有iOS版本的模拟器和实际设备 . 实时广告适用于所有iOS版本的模拟器 . 实时广告可在iOS 10实际设备上运行,但它们无法在iOS 11实际设备上运行(iOS 11上的iPhone SE) . 这也是从商店下载的实时应用程序的情况 .

它必须归功于iOS 11中的新功能 .

我收到 Banner 广告和插页式广告的错误消息:

“adView:didFailToReceiveAdWithError:请求错误:无广告显示 . ”

我将在下面显示我的代码 .

我也尝试重新安装该应用程序 . 我已尝试在AdWords帐户中更新结算信息,并检查了限制广告跟踪是否已停用 . 我已经尝试过更新我的iOS 11即将推出的广告实施 . 仍然无法正常工作 . 目前使用最新版本的SDK,谷歌移动广告SDK版本:afma-sdk-i-v7.26.0 .

这是我的原始代码,仍然在iOS 10设备上的实时应用程序中运行,没有任何问题 .

-(void)implementGoogleBannerAds
{
    self.googleBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];  
    self.googleBannerView.adUnitID = @"ca-app-pub-4170137185945186/3406302758";
    self.googleBannerView.rootViewController = self;
    self.googleBannerView.delegate = self;

    // Place the ad view onto the screen.
    [self.view addSubview:self.googleBannerView]; 
    [self.googleBannerView loadRequest:[GADRequest request]];
    self.googleBannerView.hidden=NO;

}

我尝试将其更新为刚刚在iOS11的入门笔记中更新的代码Admob,但这并未改变任何内容 . 它仍然可以在模拟器和iOS10真实设备上运行,但不适用于真正的iOS 11设备 .

-(void)implementGoogleBannerAds
{
   self.googleBannerView = [[GADBannerView alloc]
                       initWithAdSize:kGADAdSizeSmartBannerPortrait];

    self.googleBannerView.adUnitID = @"ca-app-pub-4170137185945186/3406302758";
    self.googleBannerView.rootViewController = self;
    [self.googleBannerView loadRequest:[GADRequest request]];
    self.googleBannerView.delegate = self;

}

-(void)adViewDidReceiveAd:(GADBannerView *)adView {
    NSLog(@"adViewDidReceiveAd");

    self.googleBannerView.hidden=NO;
    [self addBannerViewToView:self.googleBannerView];
}

-(void)addBannerViewToView:(UIView *)bannerView {
      NSLog(@"addBannerViewToView");
    bannerView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:bannerView];
    if (@available(ios 11.0, *)) {
        // In iOS 11, we need to constrain the view to the safe area.
        [self positionBannerViewFullWidthAtBottomOfSafeArea:bannerView];
    } else {
        // In lower iOS versions, safe area is not available so we use
        // bottom layout guide and view edges.
        [self positionBannerViewFullWidthAtBottomOfView:bannerView];
    }
}

-(void)positionBannerViewFullWidthAtBottomOfSafeArea:(UIView *_Nonnull)bannerView NS_AVAILABLE_IOS(11.0) {
    // Position the banner. Stick it to the bottom of the Safe Area.
    // Make it constrained to the edges of the safe area.
    UILayoutGuide *guide = self.view.safeAreaLayoutGuide;
        [NSLayoutConstraint activateConstraints:@[
                                                  [guide.leftAnchor constraintEqualToAnchor:bannerView.leftAnchor],
                                                  [guide.rightAnchor constraintEqualToAnchor:bannerView.rightAnchor],
                                                  [guide.bottomAnchor constraintEqualToAnchor:bannerView.bottomAnchor]
                                                  ]];

}

-(void)positionBannerViewFullWidthAtBottomOfView:(UIView *_Nonnull)bannerView {
        [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                              attribute:NSLayoutAttributeLeading
                                                              relatedBy:NSLayoutRelationEqual
                                                                 toItem:self.view
                                                              attribute:NSLayoutAttributeLeading
                                                             multiplier:1
                                                               constant:0]];
        [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                              attribute:NSLayoutAttributeTrailing
                                                              relatedBy:NSLayoutRelationEqual
                                                                 toItem:self.view
                                                              attribute:NSLayoutAttributeTrailing
                                                             multiplier:1
                                                               constant:0]];
        [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                              attribute:NSLayoutAttributeBottom
                                                              relatedBy:NSLayoutRelationEqual
                                                                 toItem:self.bottomLayoutGuide
                                                              attribute:NSLayoutAttributeTop
                                                             multiplier:1
                                                               constant:0]];
}

1 回答

  • -1

    在iOS 11.1.2上,我的iPhone 7上的最新cordova-plugin-admob-pro 2.30.1AdMob iOS SDK 7.27.0有同样的问题 . 将我的设备更新到iOS 11.2.2后,问题已解决,SMART_BANNER大小 Banner 和插页式广告一致显示 .

相关问题