AdMob interstitial shown only once on iOS - ios

I'm using admob interstitial on my iOS app.
I'm able to display the interstitial only one time, any further request to display a new interstitial fails (delegate is never called by the way).
My code is as follow:
-(void) viewDidLoad
{
[super viewDidLoad];
[self allocateAndDisplayAd];
}
-(void) allocateAndDisplayAd
{
splashInterstitial_ = [[GADInterstitial alloc] init];
splashInterstitial_.adUnitID = #"ca-app-pub-MY-ID";
splashInterstitial_.delegate = self;
GADRequest *requestInterstitial = [GADRequest request];
[splashInterstitial_ loadRequest: requestInterstitial];
}
// below functions delegate are never triggered when requesting a new interstitial !!
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
[splashInterstitial_ presentFromRootViewController: self];
}
- (void)interstitial:(GADInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error
{
splashInterstitial_ = nil;
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad
{
splashInterstitial_ = nil;
}
The interstitial is properly displayed when app launches (request done from the viewDidLoad), then any new request (call to allocateAndDisplayAd) fails (no error message, delegate function never called).
I tried to set splashInterstitial_ = nil; so I'm sure the next request will reallocate a new interstitial, but no way to display more than one ad.
Any help would be appreciated.
Thanks

Ok I found my issue
Any request to show interstitial from applicationWillEnterForeground will be ignored ...
And my second request was done from applicationWillEnterForeground

Related

Admob for iOS interstitial video runs in background when loaded

I load the intersitial ad on the load of the controller. When the load finished, ad starts running automatically. The sound of the ad is heard. The load code is below:
interstitial = [[GADInterstitial alloc] initWithAdUnitID:admobInterstatialID];
GADRequest *request = [GADRequest request];
[interstitial loadRequest:request];
The show ad code is below:
if ([interstitial isReady]) {
[interstitial presentFromRootViewController:self];
}
Thanks for any help!
Check logs to see if you are getting error "Cannot present interstitial. It is not ready."
Is below code written inside load of controller?
if ([interstitial isReady]) {
[interstitial presentFromRootViewController:self];
}
You need wait till ad is loaded completely ( Specially for interstitial ads).
Please change code to
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad {
if ([interstitial isReady]) {
[interstitial presentFromRootViewController:self];
}
}

AdMob gives unexpected result while Pop

in my application, i uses AdMob’s Interstitial ad and it is working. but when i pop VC,some times StatusBar becomes hidden and Navigation Crashes.
Situation is When i Pop VC (while,Ad will be presented). otherwise AdMob and Navigation and everything is normally working.
here is my Code for displaying InterstitialAd with its Delegate Methods
-viewDidLoad
{
[super viewDidLoad];
self.interstitial = [[GADInterstitial alloc] init];
self.interstitial.adUnitID = #"ca-app-pub-3940256099942544/4411468910";
self.interstitial.delegate = self;
GADRequest *request2=[GADRequest request];
request2.testDevices = #[ GAD_SIMULATOR_ID, #"MY_TEST_DEVICE_ID" ];
[self.interstitial loadRequest:request2];
}
Delegate Method
- (void)interstitial:(GADInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error
{
NSLog(#" Error found :-> %#",[error localizedDescription]);
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
[self.interstitial presentFromRootViewController:self];
}
Change this line
[self.interstitial presentFromRootViewController:self];
to
[self.interstitial presentFromRootViewController:self.navigationController];
Because your ViewController can be popped while an add is being presented, but I hope that your navigation controller is not presented on another ViewController, and can't be dismissed - so the solution will work.

How to dismiss Interstitial ad programmatically in ios

I have integrated Interstitial Ad for my iOS app successfully. And I know on that ad view there is a close button and we can dismiss it after clicking that button.
But I want to dismiss this ad view in programmatically after 3 seconds. But I don't know what is the method to dismiss this ad.
---- UPDATED-----
- (void)viewDidLoad
{
[super viewDidLoad];
singletonClassObject=[Singleton SharedManager];
//--------ADMOB FULLSCREEN----------
self.interstitial = [[GADInterstitial alloc] init];
self.interstitial.delegate = self;
self.interstitial = [[GADInterstitial alloc] init];
self.interstitial.adUnitID = #"ca-app-pub-3940256099942544/4411468910";
GADRequest *request = [GADRequest request];
// Requests test ads on simulators.
request.testDevices = #[ GAD_SIMULATOR_ID, #"MY_TEST_DEVICE_ID" ];
[self.interstitial loadRequest:request];
//--------END OF AD MOB FULLSCREEN---------
}
This is how show the ad in a click event
if ([self.interstitial isReady]) {
[self.interstitial presentFromRootViewController:self];
}
These are the delegates that fire when app dismiss,shows etc
/// Called when an interstitial ad request succeeded.
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad {
NSLog(#"interstitialDidReceiveAd");
}
/// Called when an interstitial ad request failed.
- (void)interstitial:(GADInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"interstitialDidFailToReceiveAdWithError: %#", [error localizedDescription]);
}
/// Called just before presenting an interstitial.
- (void)interstitialWillPresentScreen:(GADInterstitial *)ad {
NSLog(#"interstitialWillPresentScreen");
}
/// Called before the interstitial is to be animated off the screen.
- (void)interstitialWillDismissScreen:(GADInterstitial *)ad {
NSLog(#"interstitialWillDismissScreen");
//[viewAdd removeFromSuperview];
[self.view removeFromSuperview];
}
/// Called just after dismissing an interstitial and it has animated off the screen.
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
NSLog(#"interstitialDidDismissScreen");
[self.view removeFromSuperview];
}
/// Called just before the application will background or terminate because the user clicked on an
/// ad that will launch another application (such as the App Store).
- (void)interstitialWillLeaveApplication:(GADInterstitial *)ad {
NSLog(#"interstitialWillLeaveApplication");
}
although undocumented, I found that interstitial can be dismissed by:
[self dismissViewControllerAnimated:YES completion:NULL];
called on the ViewController presenting the Interstitial
Backward engineering, the Interstitial must be presented by presentViewController:animated:completion:
Well Unfortunately it is not possible you can not do that.
Check out this: Cocoadocs docsets Google Mobile Ads

No ads showing admob in live iOS add

I used adMob in my iOS app. But when i test the app it shows the test ads in the simulator, but when i try to get ads on my device (Its not a developer device) then i don't get any ads. When i use my developer device i get "no ads to show". I have setup adMob used the key.
Here is my code:
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self datoUgeNummer];
// Initialize the banner at the bottom of the screen.
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
// Use predefined GADAdSize constants to define the GADBannerView.
self.adBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner origin:origin];
// Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID before compiling.
self.adBanner.adUnitID = #"ca-app-pub-4641309369865580/3940179951";
self.adBanner.delegate = self;
self.adBanner.rootViewController = self;
[self.view addSubview:self.adBanner];
[self.adBanner loadRequest:[self request]];
}
-(void)dealloc {
_adBanner.delegate = nil;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
#pragma mark GADRequest generation
-(GADRequest *)request {
GADRequest *request = [GADRequest request];
// Make the request for a test ad. Put in an identifier for the simulator as well as any devices
// you want to receive test ads.
//request.testDevices = #[
// TODO: Add your device/simulator test identifiers here. Your device identifier is printed to
// the console when the app is launched.
// GAD_SIMULATOR_ID
// ];
return request;
}
#pragma mark GADBannerViewDelegate implementation
// We've received an ad successfully.
-(void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(#"Received ad successfully");
}
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"Failed to receive ad with error: %#", [error localizedFailureReason]);
}
Do i also need Google Analytics to get adMob working ?
I hope you understand my english and can help me! :)

iAd errors in AdBannerView

I have a test application with ads only in, for testing setup. It is setup to use admob mediation service, with iAd and admob ads being sent to the device.
I am seeing the following error occurs:
[AppDeveloper]: ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=3 "The operation couldn’t be completed. Ad inventory unavailable" UserInfo=0x9f82850 {ADInternalErrorCode=3, ADInternalErrorDomain=ADErrorDomain, NSLocalizedFailureReason=Ad inventory unavailable}
Strange error as I have implemented the method for didFailToReceiveAdWithError, here is my full imp code.
- (void)viewDidLoad {
[super viewDidLoad];
// Create a view of the standard size at the top of the screen.
// Available AdSize constants are explained in GADAdSize.h.
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = kAdMobPublisherID;
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
bannerView_.delegate = self;
bannerView_.backgroundColor = [UIColor blueColor];
GADRequest *request = [GADRequest request];
// Make the request for a test ad. Put in an identifier for
// the simulator as well as any devices you want to receive test ads.
request.testDevices = [NSArray arrayWithObjects:
#"4D047EB9-A3A7-441E-989E-C5437F05DB04",
#"YOUR_DEVICE_IDENTIFIER",
nil];
}
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error;
{
NSLog(#"Error - did Fail to Receive an Ad");
bannerView_.hidden = YES;
}
- (void)adViewDidReceiveAd:(GADBannerView *)view;
{
NSLog(#"Ad Received");
bannerView_.hidden = NO;
}
try to put return self; at the end of the methods so the delegate receives the error

Resources