Interstitial is showing just once after fourth click. Can someone do it to show for example on every click I want (on 10 th click, on 20 th click...)
if ([self.interstitial isReady]) {
if (count > 4){
[self.interstitial presentFromRootViewController:self];
count = 0;
}
}
count += 1;
if ([self.interstitial isReady]) {
[self.interstitial presentFromRootViewController:self];
}
Delete Conditions
- (GADInterstitial *)createAndLoadInterstitial
{
GADInterstitial *interstitial = [[GADInterstitial alloc] init];
interstitial.adUnitID = #"ca-app-pub-yourAdId";
interstitial.delegate = self;
[interstitial loadRequest:[GADRequest request]];
return interstitial;
}
Please get this method on application launch, then you can set follow method for many time everywhere:
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
if ([appDelegate.interstitial isReady]) {
[appDelegate.interstitial presentFromRootViewController:self];
}
Related
Every time I open category the Interstitial appears I want to make it appears once
the code
//----------Interstitial Initialization-------------//
-(void)createAndLoadInterstitial
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
_interstitial = [[GADInterstitial alloc] initWithAdUnitID:appDelegate.InterstitialAdUnitID];
_interstitial.delegate = self;
[_interstitial loadRequest:[GADRequest request]];
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial
{
[_interstitial presentFromRootViewController:self];
}
- (void)interstitial:(GADInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error
{
NSLog(#"interstitialDidFailToReceiveAdWithError: %#", [error localizedDescription]);
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial
{
NSLog(#"interstitialDidDismissScreen");
}
Try this
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
//call your method here
[self createAndLoadInterstitial];
});
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 have a sprite-kit game, and the first ad loads on gameOver, but the following gameOver's after that give the following error :
<Google> No UIViewController supplied to the ad. Cannot continue.
This is how my code looks:
initWithSize:
-(id)initWithSize:(CGSize)size {
if (...]) {
...
self.interstitial = [[GADInterstitial alloc] init];
self.interstitial.adUnitID = #"ca-app-pub-9147160832662960/2548046734";
GADRequest *request = [GADRequest request];
// Requests test ads on simulators.
[self.interstitial loadRequest:request];
...
}
return self;
}
gameOver:
-(void)gameOver
{
self.isGameOver = YES;
...
if ([self.interstitial isReady]) {
self.interstitial.delegate = self;
[self.interstitial presentFromRootViewController:_viewController];
}
...
}
scene.viewController = self.viewController;
This is what was required to be added to the initWithSize in my GameScene.
Works perfectly now
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];
}
iOS App is crashing, if we try to present a view after dismissing the Google Mobile Ads Splash Interstitial.
Simulator Version : iOS 7.1(4 inch 64 bit)
Google Mobile Ads SDK Version : 6.9.2
Code for presenting splash ad(application:didFinishLaunchingWithOptions:) :
InitialSlidingViewController *controller = [[InitialSlidingViewController alloc] init];
[self.window setRootViewController:controller];
splashInterstitial_ = [[DFPInterstitial alloc] init];
splashInterstitial_.adUnitID = SplashInterstitialID;
GADRequest *request = [GADRequest request];
splashInterstitial_.delegate = self;
request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
[splashInterstitial_ loadAndDisplayRequest:request
usingWindow:window_
initialImage:[UIImage imageNamed:imageName]];
[self.window setBackgroundColor:[UIColor blackColor]];
[self.window makeKeyAndVisible];
Delegate Methods used
- (void)interstitial:(DFPInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error {
//present a view
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
ad.delegate = nil;
splashInterstitial_.delegate = nil;
ad = nil;
splashInterstitial_ = nil;
//Present a view controller
}
Code used for presenting view
NewViewController *newVC = [[NewViewController alloc] initWithNibName:#"NewViewController" bundle:nil];
UINavigationController *nav = [[PortraitNavController alloc] initWithRootViewController:newVC];
nav.navigationBarHidden = YES;
[self.navigationController presentViewController:nav animated:YES completion:nil];
//Crash Log from console:
* -[GADWebAppViewController isKindOfClass:]: message sent to deallocated instance 0x573efe90
Solved this issue by moving the code for presenting interstitial to Rootviewcontroller. This solution is recommended in Google Ads Developer official blog.
//MyRootViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Remember whether the status bar was hidden or not.
hideStatusBar_ = [UIApplication sharedApplication].statusBarHidden;
splashInterstitial_ = [[DFPInterstitial alloc] init];
splashInterstitial_.adUnitID = SplashInterstitialID;
splashInterstitial_.delegate = self;
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
[splashInterstitial_ loadRequest:request];
}
#pragma mark - splashInterstitial delegate methods
- (void)restoreController {
if (imageView_ != nil) {
[imageView_ removeFromSuperview];
}
[UIApplication sharedApplication].statusBarHidden = hideStatusBar_;
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad {
[splashInterstitial_ presentFromRootViewController:self];
}
- (void)interstitial:(DFPInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error {
[self restoreController];
}
- (void)interstitialWillDismissScreen:(GADInterstitial *)ad {
[self restoreController];
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
//Dismiss Delegate
}
imageView_ is a full screen image view contains the same splash screen image.