AdMob gives unexpected result while Pop - ios

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.

Related

iOS app crash when presenting multiple Admob Mediated Interstitials

I have implemented Admob in my iOS application. Banners, rewarded videos and mediated interstitials (Admob, Unity and Chartboost). The only problem I have is that the app always crash after 3-4 interstitial ads has been presented. The debugger shows this message: Message from debugger: Terminated due to memory issue.
I am 100% sure the crash comes from the Interstitials. I have tested completely without ads, no crash. And only with banner ads, no crash.
This is the code I use to implement and show Interstitial ads:
#interface ViewController ()
#property(nonatomic, strong) GADInterstitial *interstitial;
#end
- (void)viewDidLoad {
[self loadInterstitial];
}
- (void)loadInterstitial {
self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:#"ca-app-pub-xxxxx/xxxxx"];
self.interstitial.delegate = self;
[self.interstitial loadRequest:[GADRequest request]];
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial {
[self loadInterstitial];
}
- (void)someMethod {
if (self.interstitial.isReady) {
[self.interstitial presentFromRootViewController:self];
}
}

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];
}
}

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

AdMob interstitial shown only once on 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

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! :)

Resources