i want to be able to request interstitial test ads on iOS on the simulator
this is the code I'm using
interstitial_ = [[GADInterstitial alloc] init];
interstitial_.adUnitID = #"XXXXXXXXXXXXXXXX";
[interstitial_ loadRequest:[GADRequest request]];
interstitial_.delegate = self;
thanks.
Not sure about your specific question. But, the Google Mobile Ads SDK documentation is very rich. Here's the code which I often use -
- (void)loadAdMobIntersBanner
{
interstitial_ = [[GADInterstitial alloc] init];
interstitial_.adUnitID = #"ca-app-pub-xxxxxxxxx/xxxxxxx";
interstitial_.delegate = self;
GADRequest *request = [GADRequest request];
[interstitial_ loadRequest:request];
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
[interstitial_ presentFromRootViewController:self];
}
Related
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.
I've having issues with creating an admob ad which will be shown on the simulator and the device. At the moment i't will only show on the simulator. Here i get an ad which say: PUBLISHER TEST AD.
I've searched for sometime, but cant find an solution
Why wont it show on the device as well?
- (void)viewDidLoad
{
self.bannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-50, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
self.bannerView.adUnitID = myAdUnitID;
self.bannerView.delegate = self;
[self.bannerView setRootViewController:self];
[self.view addSubview:self.bannerView];
[self.bannerView loadRequest:[self createRequest]];
[self.navigationController.tabBarController.tabBar setHidden:YES];
}
-(GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
return request;
}
-(void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(#"Ad Received");
[UIView animateWithDuration:1.0 animations:^{
adView.frame = CGRectMake(0.0, self.view.frame.size.height-50, adView.frame.size.width, adView.frame.size.height);
}];
}
-(void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"error due to: %#", [error localizedFailureReason]);
}
Admobs ad only shows on the simulator
Because You Added GAD_SIMULATOR_ID in this line of code so it showing only testing ads on simulator.
[NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
So my opinion is you can test on device as if you add your device id in this array.So every time when you open this app this will show you test add and as soon possible if add available on Google Admob this will show you the ad and start showing Impression on your Admob account.
I am unable to receive mobile adds in my app.
My code is here:-
-(void) createMObAdds
{
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
// Specify the ad unit ID.
bannerView_.adUnitID = #"d81cb38a93cc479";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
}
- (GADRequest *)request
{
GADRequest *request = [GADRequest request];
request.testDevices = #[GAD_SIMULATOR_ID];
[request setTesting:YES];
return request;
}
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(#"Received ad successfully");
}
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"Failed to receive ad with error: %#", [error localizedFailureReason]);
}
But I am getting ERROR :Request Error: A network error occurred.
Please let me know where is the problem in my code or what I need to do ?.
Please see below Google Developer Link which guide you step by step
Google Developer AdMob Guide
hope it Help full to you