I am unable to receive mobile adds in my app.
My code is here:-
-(void) createMObAdds
{
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
// Specify the ad unit ID.
bannerView_.adUnitID = #"d81cb38a93cc479";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
}
- (GADRequest *)request
{
GADRequest *request = [GADRequest request];
request.testDevices = #[GAD_SIMULATOR_ID];
[request setTesting:YES];
return request;
}
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(#"Received ad successfully");
}
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"Failed to receive ad with error: %#", [error localizedFailureReason]);
}
But I am getting ERROR :Request Error: A network error occurred.
Please let me know where is the problem in my code or what I need to do ?.
Please see below Google Developer Link which guide you step by step
Google Developer AdMob Guide
hope it Help full to you
Related
Question:(iOS)
i want to display GADInterstitialAd at ApplicationDidBecomeActive in AppDelegate. bellow is the code i'm using
- (void)showInterstitial{
GADRequest *request = [GADRequest request]; // here you need to crate object of GADRequest
request.testDevices = #[ kGADSimulatorID ];
GADInterstitial* interstitialAd = [[GADInterstitial alloc]initWithAdUnitID:AdvertismentID];
interstitialAd.delegate = self;
[interstitialAd loadRequest:request];
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
[interstitial presentFromRootViewController:pagerViewController];
}
- (void)interstitial:(GADInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error {
// [[UIApplication sharedApplication] setStatusBarHidden:FALSE withAnimation:NO];
NSLog(#"==%#",[error localizedDescription]);
}
-(void)interstitialWillPresentScreen:(GADInterstitial *)ad{
// [[UIApplication sharedApplication] setStatusBarHidden:TRUE withAnimation:NO];
NSLog(#"on screen");
}
and i'm calling [self showInterstitial] in ApplicationDidBecomeActive i've added <GADInterstitialDelegate> but delegate methods are not calling even i'm not getting errors. please help me.
OK, i got the answer.
simply used strong reference of GADInterstitialAd in above code.
I am using IOS Google Admob SDK 6.11.1 and Xcode 5.1.
If I thought loadrequest is replacement for loadanddisplayrequest but its not.
[splashInterstitial_ loadRequest:[GADRequest request]];
Because intertitial never appears by using loadrequest only.
loadAndDisplayRequest this method is working but I want to know whats the replacement for this deprecated method.
You need to call presentFromRootViewController: after you've received the interstitial:
#pragma mark - GADInterstitialDelegate
- (void)interstitialDidReceiveAd:(DFPInterstitial *)ad
{
[splashInterstitial_ presentFromRootViewController:self];
}
Use this code in appdelegate .it's working for me.
- (void)applicationDidBecomeActive:(UIApplication *)application
{
GADRequest *request = [GADRequest request]; // here you need to crate object of GADRequest
interstitial_ = [[GADInterstitial alloc] init];
interstitial_.adUnitID =#"ca-app-pub-43434/343434";
interstitial_.delegate = self;
// request.testDevices = [NSArray arrayWithObjects:
// #"MY_SIMULATOR_IDENTIFIER",
// #"fbb99fa8c725017137fb191a20aa342491b82a37",
// nil];
[interstitial_ loadRequest:request];
}
- (void)interstitial:(GADInterstitial *)interstitial
didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"==%#",[error localizedDescription]);
}
-(void)interstitialWillPresentScreen:(GADInterstitial *)ad{
NSLog(#"on screen");
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
// [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
[interstitial presentFromRootViewController:self.window.rootViewController];
// [interstitial presentFromRootViewController:self];
}
i want to be able to request interstitial test ads on iOS on the simulator
this is the code I'm using
interstitial_ = [[GADInterstitial alloc] init];
interstitial_.adUnitID = #"XXXXXXXXXXXXXXXX";
[interstitial_ loadRequest:[GADRequest request]];
interstitial_.delegate = self;
thanks.
Not sure about your specific question. But, the Google Mobile Ads SDK documentation is very rich. Here's the code which I often use -
- (void)loadAdMobIntersBanner
{
interstitial_ = [[GADInterstitial alloc] init];
interstitial_.adUnitID = #"ca-app-pub-xxxxxxxxx/xxxxxxx";
interstitial_.delegate = self;
GADRequest *request = [GADRequest request];
[interstitial_ loadRequest:request];
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
[interstitial_ presentFromRootViewController:self];
}
I've having issues with creating an admob ad which will be shown on the simulator and the device. At the moment i't will only show on the simulator. Here i get an ad which say: PUBLISHER TEST AD.
I've searched for sometime, but cant find an solution
Why wont it show on the device as well?
- (void)viewDidLoad
{
self.bannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-50, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
self.bannerView.adUnitID = myAdUnitID;
self.bannerView.delegate = self;
[self.bannerView setRootViewController:self];
[self.view addSubview:self.bannerView];
[self.bannerView loadRequest:[self createRequest]];
[self.navigationController.tabBarController.tabBar setHidden:YES];
}
-(GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
return request;
}
-(void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(#"Ad Received");
[UIView animateWithDuration:1.0 animations:^{
adView.frame = CGRectMake(0.0, self.view.frame.size.height-50, adView.frame.size.width, adView.frame.size.height);
}];
}
-(void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"error due to: %#", [error localizedFailureReason]);
}
Admobs ad only shows on the simulator
Because You Added GAD_SIMULATOR_ID in this line of code so it showing only testing ads on simulator.
[NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
So my opinion is you can test on device as if you add your device id in this array.So every time when you open this app this will show you test add and as soon possible if add available on Google Admob this will show you the ad and start showing Impression on your Admob account.
I am using Admob in my app.
I am getting following error:
[GADDelegateManager didYouNilOutYourDelegate:selector:] at GADDelegateManager.m:48
I am releasing my Admob Banner object in dealloc.
Can anyone tell what can be the possible fix for this error.
-(void)displayAds {
self.aBannerView.adUnitID = AdmobPublisherID;
[self.aBannerView setDelegate:self];
[self.aBannerView setRootViewController:roorViewController];
if (isAdLoaded) {
[self.view addSubview:self.aBannerView];
} else {
// Initiate a generic request to load it with an ad.
[self.view addSubview:self.aBannerView];
[self.aBannerView loadRequest:[self createRequest]];
isAdLoaded = YES;
}
}
#pragma mark GADRequest generation
- (GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects: nil];
return request;
}
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(#"Received ad successfully popup");
if(self.aBannerView !=nil) {
self.aBannerView.hidden = NO;
}
}
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"Failed to receive ad with error: %#", [error localizedFailureReason]);
[self.aBannerView removeFromSuperview];
[self showInhouseAd];
}
- (void)adViewWillLeaveApplication:(GADBannerView *)bannerView {
}
- (void)dealloc {
[aBannerView release];
}
Thanks,
The selector name seems rather explanatory to me. Try setting the delegate to nil before releasing the banner view:
- (void)dealloc {
[aBannerView setDelegate:nil];
[aBannerView release];
}
As the error actually says [GADDelegateManager didYouNilOutYourDelegate:selector:]. I would actually try
- (void)dealloc
{
aBannerView.delegate = nil;
[aBannerView release];
}
That seems like your problem as indicated by the error message.