@property(nonatomic,strong)GADBannerView *bannerView;
@end
@implementation ViewController
- (void)viewDidLoad {
....
[GADMobileAds configureWithApplicationID:@"ca-app-pub-YYYYYYY~YYYYYYY"];
_bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
_bannerView.center = CGPointMake(self.view.center.x, _adSize.size.height/2.f + 44/2.f + 50/2.f);
_bannerView.adUnitID = @"ca-app-pub-XXXXXXXXXX/XXXXXXXX";
_bannerView.rootViewController = self;
_bannerView.delegate = self;
GADRequest * request = [GADRequest request];
request.testDevices = @[kGADSimulatorID];
[_bannerView loadRequest:request];
[self.view addSubview: _bannerView];
}
#pragma mark -
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView {
NSLog(@"Admob Ad was loaded and ready to be displayed");
}
- (void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(@"Admob Ad failed to load");
}
Error:
Error Domain=com.google.ads Code=13 "Request Error: Received invalid response." UserInfo={NSLocalizedDescription=Request Error: Received invalid response., NSLocalizedFailureReason=Request Error: Received invalid response.}
Solution:
1. Make Sure your adUnitID and ApplicationID are correct.
2. Add request.testDevices = @[kGADSimulatorID];
3. iOS 9 or iOS 10 app please in Info.plist add "App Transport Security Settings" - "Allow Arbitrary Loads" set to "Yes"
You will get the test ads

No comments:
Post a Comment