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];
}
}
Related
I'm using Admob interstitial in my app.
I followed all the guidelines and I observe Video interstitial are presented automatically while I did not call yet presentFromRootViewController.
I'm using that code to preload the interstitial :
splashInterstitial_ = [[GADInterstitial alloc] initWithAdUnitID: interstitialIdStr];
splashInterstitial_.delegate = self;
requestInterstitial = [GADRequest request];
[splashInterstitial_ loadRequest: requestInterstitial];
In the delegate, I do not present the interstitial :
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
}
I present the interstitial manually between two screens, as follow :
if (splashInterstitial_.isReady)
{
[splashInterstitial_ presentFromRootViewController: interstitialRootViewController];
self.lastInterstitialTime = [[NSDate date] timeIntervalSince1970];
return YES;
}
I placed a breakpoint on presentFromRootViewController, the breakpoint is never reached, and I can see interstitial videos presented on real device.
I sounds like the loadRequest on interstitial triggers a presentation which should not occur.
Anybody experiencing a similar issue ?
Thanks
i'm searching on google but i only find the way to integrate the AdMob Banner View on my app in Cocos2d. Now I need to put the full screen AdMob interstitial and i don't find the way to do it :. Please Help me, how i can do it??
I'm not sure what source code i need to post... I would like to show the interstitial when the app startup and when there is the game over.
I already tried this
but it gave me some error.
In AppDelegate.h, add GADInterstitialDelegate
#interface AppController : NSObject <UIApplicationDelegate, CCDirectorDelegate, GADInterstitialDelegate>
{
}
-(void)showAdmobFullScreenAds;
#end
#define App ((AppController *)[[UIApplication sharedApplication] delegate])
In AppDelegate.m
-(void)showAdmobFullScreenAds
{
GADInterstitial *interstitial_ = [[GADInterstitial alloc] init];
interstitial_.adUnitID = #"ca-app-pub-YOUR_ID";
interstitial_.delegate = self;
[interstitial_ loadRequest:[GADRequest request]];
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial
{
[interstitial presentFromRootViewController:[CCDirector sharedDirector]];
}
// In GameOver class, add #import "AppDelegate.h" then use below function
[App showAdmobFullScreenAds];
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
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
I'm currently getting a crash thats holding my app out of the app store, it seems to occur when i create a google ad as a fall back for iAd.
It only occurs on the I-pad running IOS 6.0 - 6.1 in compatibility mode (the app is not universal) and it appears to occur after the:
[googleAdvertBanner loadRequest:releaseRequest];
Any help would be really appreciated, here's what i'm getting in the code view when i crash:
GADMAdNetworkConnectorImpl.m:95
0x49e008: addl $60, %esp --- Thread 1:EXEC_BAD_ACCESS (code=2, address=0xf)
The log shows the following:
DBannerView: 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=0x13c9e380 {ADInternalErrorCode=3, ADInternalErrorDomain=ADErrorDomain, NSLocalizedFailureReason=Ad inventory unavailable}
And my app code for the ad handling:
#pragma mark Ad Banner Delegate
#pragma mark -
- (void)bannerViewDidLoadAd:(ADBannerView *)banner{
// remove the google advert banner
[googleAdvertBanner removeFromSuperview];
// dont use auto resizing mask for constraints
advertBanner.translatesAutoresizingMaskIntoConstraints = NO;
// scroll the ad bar
[self moveViews:adView down:YES];
//NSLog(#"IAD advert has SUCCEEDED");
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
// scroll the ad bar
[self moveViews:adView down:NO];
// create the google advert
[self createGoogleAdvert];
//NSLog(#"IAD advert has FAILED");
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner{
}
#pragma mark GoogleAd Banner Delegate
#pragma mark -
- (void)adViewDidReceiveAd:(GADBannerView *)view{
// dont use auto resizing mask for constraints
googleAdvertBanner.translatesAutoresizingMaskIntoConstraints = NO;
// add the google advert banner
[adView addSubview:googleAdvertBanner];
// scroll the ad bar
[self moveViews:adView down:YES];
//NSLog(#"Google advert has SUCCEEDED");
}
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error{
// remove the google ad and instantiate the apple advert
[googleAdvertBanner removeFromSuperview];
// scroll the ad bar
[self moveViews:adView down:NO];
//NSLog(#"Google advert has FAILED");
}
- (void)adViewDidDismissScreen:(GADBannerView *)adView{
}
#pragma mark Create GoogleAd Banner
#pragma mark -
- (void)createGoogleAdvert{
// if the googleadvert banner has not been initiated
if (!googleAdvertBanner) {
// create google advert banner
googleAdvertBanner = [[GADBannerView alloc]initWithAdSize:kGADAdSizeBanner];
}
// set the ads "unit identifier", delegate and root view controller
googleAdvertBanner.adUnitID = #"myid which is correct";
googleAdvertBanner.delegate = self;
googleAdvertBanner.rootViewController = self;
// test request
//GADRequest *testRequest = [GADRequest request];
//testRequest.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, #"0525457c40445ae54cac4f282ba0d409", nil];
// release request
GADRequest *releaseRequest = [GADRequest request];
// load the request
[googleAdvertBanner loadRequest:releaseRequest];
}
Try to check internet reachability before performing GADRequest. I had experience with crashing on loading adMob banners offline.
if ([[Reachability reachabilityForInternetConnection] isReachable]) {
//... banner init etc
// release request
GADRequest *releaseRequest = [GADRequest request];
// load the request
[googleAdvertBanner loadRequest:releaseRequest];
}
Ok think i solved this issue:
I had my admob mediation also serving the iAd as well as having an adbannerview, and i believe that on the lower end IOS version 6.0-6.1 When the mediated iAd failed it was unable to call the failedToLoad as the adbannerview did not exist or it was simply couldnt run the method, removing the mediation from my admob setup solved the crash.