Google Admob live ads not showing in iOS 11 on real device
I have searched and found posts online and on StackOverflow which have the same or similar error message as me, but none of them are having the same bug as me. They have different conditions ie the error message appears in different situations or they are on a different version of iOS etc. I've tried all the solutions i've found online.
Basically I am using Admob to show banner ads and interstitial ads in my iOS app. These have been running in the live app for over a year, they are still currently running live in iOS 10 devices and earlier versions of iOS, without any problems .
But when iOS updated to iOS11, things changed.
Test ads work on the simulator and actual devices on all versions of iOS. The live ads work on the simulator on all versions of iOS. Live ads work on an iOS 10 actual device but they do not work on an iOS 11 actual device(iPhone SE on iOS 11). This is also the case for the live app downloaded from the store.
It must be due to something new in iOS 11.
I get the error message below for the banner ad and interstitial ad:
"adView:didFailToReceiveAdWithError: Request Error: No ad to show.”
I'll show my code below.
I've also tried reinstalling the app. I've tried updating my billing information in my AdWords account and I've checked that Limit Ad Tracking is disabled. I've also tried updating my implementation of the ads now that iOS 11 is out. Still doesn't work. Currently using the latest version of the SDK, Google Mobile Ads SDK version: afma-sdk-i-v7.26.0.
Here is my original code thats still running in the live app on iOS 10 devices without any problems.
-(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;
}
I tried updating this to the code Admob just updated in their Get Started notes for iOS11 but this didn't change anything. It still works in the simulator and on iOS10 real devices but not a real iOS 11 device.
-(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]];
}
I had the same problem with the latest cordova-plugin-admob-pro 2.30.1 with AdMob iOS SDK 7.27.0 on my iPhone 7 when on iOS 11.1.2. After updating my device to iOS 11.2.2 the problem has been solved and SMART_BANNER size Banner and Interstitial ads display consistently.
链接地址: http://www.djcxy.com/p/32280.html