Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying admob interstitals multiple times how?

I have small gaming app which has one storyboard and inside it creates scenes like start menu-gamin area-scores I have added admob banner view and interstitals into it.My banner view is working fine and but my interstitial only works for one time.

I load my interstitial on my viewdidload and fire it in the function which calls the gaming sessions end and as I say it works but only for one time when user starts another game and fails this time there is no interstital(error below).So what should I do to fix it I want my game to show interstitials multiple times whenever I want.

Error : Request Error: Will not send request because interstitial object has been used.

Header:

#import "GADBannerView.h"
#import "GADInterstitial.h"
@class GADInterstitial;
@class GADRequest;
////////////code UIviewcontroller//////////
        GADBannerView *bannerView_;
        GADInterstitial *interstitial_;

Implementation

-(void)viewdidload
{
//////////////////gaming code///////////

interstitial_ = [[GADInterstitial alloc] init];
    interstitial_.delegate = self;

    interstitial_.adUnitID = @"ca-app-pub-6280395701552972/5217388242";
    GADRequest *request = [GADRequest request];
    [interstitial_ loadRequest:request];

}

Implementaion

-(void)failgame
{
//////////////////gaming code///////////

    [interstitial_ presentFromRootViewController:self];

}

On googleadmob SDK page it says that interstials are one time use objects so I am %100 sure that is the problem but there is nothing there to explain how to call them multiple time's so as long as you point the answer please don't tell go read it I have read it 5 times.

like image 210
Bugra Sezer Avatar asked Jun 22 '14 16:06

Bugra Sezer


People also ask

How often to show interstitial ads?

If your app is not a game but has many pages or sections, consider placing an interstitial ad after a number of screens or actions taken. Avoid placing an interstitial ad every single time the user does an action. It is recommended that interstitial ads appear before the break page rather than after.

Where do interstitial ads go?

Interstitial ads are full-screen ads that cover the interface of their host app. They're typically displayed at natural transition points in the flow of an app, such as between activities or during the pause between levels in a game.

What does interstitial mean in advertising?

An interstitial ad is a full-screen ad that covers the entire interface of the host app. These ads are designed to be placed between content, and are typically displayed at transition points in an app flow, such as between activities, during a pause, or between levels in a game.


2 Answers

Well no one gave an answer but I am sure that there are some others out there who had the same problem so for those who want to call interstitals multiple times here is the trick.

Put it into its own method and call method from your main method (which replies many times)

Keep the interstitals on your viewdidload (or where you want fire first) because if you don't then you miss the first fire the others will work.

The full code for that.

- (void) callint
{
    int rNumber1 = arc4random() % 45 + 1;
    int rNumber2 = arc4random() % 45 + 1;
    if((rNumber1%2==1) && (rNumber1%1==0))
    {
    [interstitial_ presentFromRootViewController:self];
    interstitial_ = [[GADInterstitial alloc] init];
    interstitial_.delegate = self;
    interstitial_.adUnitID = @"ca-app-pub-6280395701552972/5217388242";
    GADRequest *request = [GADRequest request];
    [interstitial_ loadRequest:request];

    }

}

I put random number creation and if there because I don't want users to see those intersitials every time even call int is fired every time there is 4/1 chance for it to fire so it shows 1 interstitial for 4-5 fire.

like image 99
Bugra Sezer Avatar answered Oct 12 '22 23:10

Bugra Sezer


- (void)viewDidLoad {
  [super viewDidLoad];
  self.interstitial = [self createAndLoadInterstitial];
}

- (GADInterstitial *)createAndLoadInterstitial {
  GADInterstitial *interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/4411468910"];
  interstitial.delegate = self;
 [interstitial loadRequest:[GADRequest request]];
  return interstitial;
}

- (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial {
  self.interstitial = [self createAndLoadInterstitial];
}

GADInterstitial is a one time use object. To request another interstitial, you'll need to allocate a new GADInterstitial object.

The best place to allocate another interstitial is in the interstitialDidDismissScreen: method on GADInterstitialDelegate, so that the next interstitial starts loading as soon as the previous one is dismissed. reference: admob site link

like image 27
dev Avatar answered Oct 12 '22 23:10

dev