Test iAds are good, but live iAds fail - ios

When my app was in development, iAds worked great. Every 30 seconds I would either get a call to "bannerViewDidLoadAd" or to "didFailToReceiveAdWithError" and I prepared the app to handle either callback. I get the green checkmark "You're connected to iAd's App Network" and the other test ads.
Now that the app is live, it only gets "didFailToReceiveAdWithError" and never loads an ad.
I'm running the released version of the app on my phone plugged in to the Xcode Organizer Console, and I see the NSLog that prints within "didFailToReceiveAdWithError"
The iAd Portal doesn't show any requests though, it lists 0 requests.
I've built it to my phone again from XCode with the development profile and again it works as it should. I've deleted the app, shut down my phone, signed out of my iTunes Apple ID, and redownloaded the app from the App Store and still the ad fails every time.
Here's how I've got the ad coded:
In my rootViewController, the user chooses to start a new game, and I animate the new view:
UIViewController *nextController = [[GamePlayViewController alloc] initWithNibName:#"GamePlayView" bundle:nil];
[nextController performSelector:#selector(setDelegate:) withObject:self];
nextController.view.frame = CGRectMake(0, 570, 320, 568);
[self.view addSubview:nextController.view];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.23];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
nextController.view.frame = CGRectMake(0, 0, 320, 568);
[UIView commitAnimations];
temporaryController = nextController;
GamePlayViewController.h includes:
- #import <iAd/iAd.h>
- #interface GamePlayViewController : UIViewController <ADBannerViewDelegate, UIDocumentInteractionControllerDelegate> {
GamePlayViewController.m includes:
- ADBannerView *_bannerView;
Once the user is in GamePlayViewController.m, there is an animation triggered in viewDidLoad, and once that animation completes, an ad is called:
if ([ADBannerView instancesRespondToSelector:#selector(initWithAdType:)]) {
_bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
} else {
_bannerView = [[ADBannerView alloc] init];
}
_bannerView.delegate = self;
[self.view bringSubviewToFront:_bannerView];
}
That's really all there is to it other than the callback methods for iAds.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(#"ad loaded!");
_bannerView.hidden = NO;
[self layoutAnimated:YES];
}
- (void)layoutAnimated:(BOOL)animated
{
// As of iOS 6.0, the banner will automatically resize itself based on its width.
// To support iOS 5.0 however, we continue to set the currentContentSizeIdentifier appropriately.
CGRect contentFrame = self.view.bounds;
if (contentFrame.size.width < contentFrame.size.height) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
CGRect bannerFrame = _bannerView.frame;
if (_bannerView.bannerLoaded) {
bannerFrame.origin.y = 0;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}
[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
_contentView.frame = contentFrame;
[_contentView layoutIfNeeded];
_bannerView.frame = bannerFrame;
[self.view addSubview:_bannerView];
}];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"ad failed!");
_bannerView.hidden = YES;
}
Maybe something I am doing is wrong or I should have the ad on the rootViewController itself, but this code works great with test iAds, so I'm not sure why it's not working with the App Store version of the app.
Thanks for any help!

I've not looked at your code but I've observed this also. Sometimes Apple just hasn't sold any ads so there aren't any to display for you. Consider using an ad aggregator. I use https://github.com/larsacus/LARSAdController but modified it to display ads the way I want to.
I cover that in my blog entry: http://www.notthepainter.com/iad-admob-integration-with-a-dynamic-uiview/
Here is the text of the blog entry so it is preserved here, just in case my blog goes away someday.
I’ve released 2 apps both with iAds. I used Apple’s BannerView sample code to implement this. Basically, in your delegate you don’t set root to your expected root UIViewController but rather you set root to a BannerView which contains your real root. When an iAd is available, your main view shrinks and the iAd is displayed at the bottom. When an ad isn’t available, your view expands to its “normal” size.
This worked very well in testing so I released both apps to the app store. They’re Done Yet? and Wheelin. However, when I first downloaded the versions from the store I was quite surprised to see no ads ever. It turns out that at least right now, iAd had a pretty horrible fill rate. So I wanted to show another ad when an iAd wasn’t available.
I found LARSAdController, an open source project by larsacus on GitHub. He makes ad integration very easy except for one thing. When you go down his quick development route you get the ads covering your view, it doesn’t shrink to accommodate the ad. This is a completely reasonable design decision, just not one I wanted.
So I decided to modify Apple’s BannerView to use LARSAdController. It was pretty easy.
The first thing you do is remove iAd from BannerView’s .h file and ad in the LARS TOLAdViewController class.
#import "TOLAdViewController.h"
#define KVO_AD_VISIBLE #"KVO_AD_VISIBLE"
#interface BannerViewController : TOLAdViewController
(Just ignore the KVO_AD_VISIBLE define for now, I’ll cover that later.) In the .m file also remove iAd and make these changes:
#implementation BannerViewController {
UIView *_bannerView;
UIViewController *_contentController;
BOOL isLoaded;
}
We changed _bannerView from an ADBannerView into a plain old UIVIew. ADBannerView also has a bannerLoaded property which we’ll have to replace with our isLoaded boolean. initWithContentViewController is also easy to modify.
// IAPHelper *sharedInstance = [//IAPHelper sharedInstance];
//if ([sharedInstance showBannerAds]) {
if (YES) {
_bannerView = [[UIView alloc] initWithFrame:CGRectZero];
} else {
_bannerView = nil; // not showing ads since the user has upgraded
}
Notice the commented out section. If you are using in-app purchases to transform an ad supported version into an ad free version you can do that right there.
At the end of the method well use Key-Value-Observing (KVO) to watch LARS and see when an ad is served or removed. (I’ll probably cover KVO in a future blog entry.)
[[LARSAdController sharedManager] addObserver:self
forKeyPath:kLARSAdObserverKeyPathIsAdVisible
options:0
context:KVO_AD_VISIBLE];
And the observing code:
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context;
{
if(context == KVO_AD_VISIBLE) {
NSNumber *isVisible = [object valueForKey:kLARSAdObserverKeyPathIsAdVisible];
if ([isVisible boolValue]) {
_bannerView.frame = [[LARSAdController sharedManager] containerView].frame;
isLoaded = YES;
} else {
isLoaded = NO;
}
}
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}
We save the frame of the new ad and also update the isLoaded variable. (Originally thought I would need to call setNeedsLayout and layoutIfNeeded but in practice I didn’t.) The mods to viewDidLayoutSubviews were also pretty straightforward. The only odd part was removing the references to ADBannerContentSizeIdentifierPortrait and ADBannerContentSizeIdentifierLandscape and just replacing that all with a single line:
bannerFrame.size = [_bannerView sizeThatFits:contentFrame.size];
And a few lines later you use the new isLoaded variable
if (isLoaded) {
Don’t forget to clean up your observer in dealloc:
-(void) dealloc;
{
[[LARSAdController sharedManager] removeObserver:self forKeyPath:kLARSAdObserverKeyPathIsAdVisible];
}
All that remains is to tell LARS about your ads in your app delegate:
[[LARSAdController sharedManager] registerAdClass:[TOLAdAdapterGoogleAds class] withPublisherId:#"a14e55c99c24b43"];
[[LARSAdController sharedManager] registerAdClass:[TOLAdAdapteriAds class]];
LARSBannerViewController *root = [[LARSBannerViewController alloc] initWithNibName:#"LARSBannerViewController" bundle:nil];
_bannerViewController = [[BannerViewController alloc] initWithContentViewController:root];
[self.window setRootViewController:_bannerViewController];
And that’s it. Now your app should show iAD or AdMob ads and your view will shrink to accommodate them.
Of course there’s a bug, I don’t know if this is in AdMob server or in LARS but when you are in Landscape mode on an iPhone the ad’s size and the reported size are different leaving a black bar at the bottom of the screen. I’ve pinged larsacus about it and will update this post when I know more.
I’ve forked LARSAdController and submitted the above sample code in a full project on my github.

After a few days, I was getting ready to call for support, and then the iAds started working. So I guess the answer is that there is potential for a lag to occur between an app going live and ads populating for that app.
Initially when the ads started coming in, the fill rate wasn't much above 50% and I was only seeing the one ad for iTunes Radio, but at least the ads had started working. Now fill rate is up to 67% and I'm seeing a bit more of a variety with the ads.

Related

View added in applicationDidEnterBackground not visible until app returns from background

I add an imageView to my app's main window in applicationDidEnterBackground:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIImageView *splash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"splashimage.png"]];
splash.frame = self.window.bounds;
[self.window addSubview:splash];
}
I expect that when I put the app into the background by pressing the device's home button, then viewing the task manager by double tapping the home button, I will see the splashimage.png displayed. But it seems that the screenshot that is taken when the app goes into the background does not include this overlay imageView. I thought that it would, since I added the imageView with no animation.
Why might this might be happening?
UPDATE: Even if I hide my window in applicationDidEnterBackground, I can still see the full window, unhidden, in the task manager after the app is put into the background state. The window only becomes hidden a moment after the app returns from the background, when I press the home button.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
//this does not work either!
self.window.hidden = YES;
}
UPDATE: I do understand, by the way, that applicationDidEnterBackground has 5 seconds to complete. I am now testing this with only
self.window.hidden = YES;
in applicationDidEnterBackground and nothing in applicationWillResignActive, and the window still is not hidden when the app goes into the background; only when it returns to the foreground. So this is telling me that there must be something else, somewhere in my app, that is not allowing this to happen in applicationDidEnterBackground. By the way, if I move the
self.window.hidden = YES;
to applicationWillResignActive, the window IS hidden when the app goes into the background. But I am trying to figure out what will inhibit an app from completing this single, simple, non-animated task in applicationDidEnterBackground. Any thoughts appreciated.
UPDATE: This particular issue has something to do with using a BannerViewController (iAd). I am using it in a UITabBarController. Not sure yet what exactly the issue is or if it is also related to its use within UITabBarController.
UPDATE: I think the issue is not related to the UITabBarController, but in general the BannerViewController (iAd). Now to understand why...
UPDATE: This line in BannerViewController.m is causing the issue:
[self.view addSubview:bannerView]
in this method:
- (void)viewDidLayoutSubviews
{
CGRect contentFrame = self.view.bounds, bannerFrame = CGRectZero;
ADBannerView *bannerView = [BannerViewManager sharedInstance].bannerView;
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
NSString *contentSizeIdentifier;
// If configured to support iOS <6.0, then we need to set the currentContentSizeIdentifier in order to resize the banner properly.
// This continues to work on iOS 6.0, so we won't need to do anything further to resize the banner.
if (contentFrame.size.width < contentFrame.size.height) {
contentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
contentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
bannerFrame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:contentSizeIdentifier];
#else
// If configured to support iOS >= 6.0 only, then we want to avoid currentContentSizeIdentifier as it is deprecated.
// Fortunately all we need to do is ask the banner for a size that fits into the layout area we are using.
// At this point in this method contentFrame=self.view.bounds, so we'll use that size for the layout.
bannerFrame.size = [_bannerView sizeThatFits:contentFrame.size];
#endif
if (bannerView.bannerLoaded) {
contentFrame.size.height -= bannerFrame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}
_contentController.view.frame = contentFrame;
// We only want to modify the banner view itself if this view controller is actually visible to the user.
// This prevents us from modifying it while it is being displayed elsewhere.
if (self.isViewLoaded && (self.view.window != nil)) {
[self.view addSubview:bannerView];
bannerView.frame = bannerFrame;
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
bannerView.currentContentSizeIdentifier = contentSizeIdentifier;
#endif
}
}
Not exactly sure why or what, if anything can be done to fix it if I still want to use BannerViewController.
UPDATE: from to the accepted answer below, here is what solved this problem for me (bannerVC is a reference to the BannerViewController).
- (void)applicationWillResignActive:(UIApplication *)application {
[bannerVC.view snapshotViewAfterScreenUpdates:YES];
}
UPDATE: I realize that this code really should be in applicationDidEnterBackground. But, it seems with AdBannerView that there is no way to stop the animations in time so that this can happen. So for now, in my understanding, applicationWillResignActive is all that is left, but it leaves the user with a 'less-than' experience. I would appreciate any suggestions on how to stop the AdBannerView animations so that the snapshot can be shown in applicationDidEnterBackground and not only when returning from the background.
UPDATE:
To replicate the issue:
Download iAdSuite
Open TabbedBanner example.
Add the code below to AppDelegate:
Run the app. (frames are messed up because it hasn't been updated but this example will still show the problem)
Tap the home button once to put the app into the background.
Double-tap the home button to see the app in the task manager.
If you have left the code in applicationWillResignActive commented and the code in applicationDidEnterBackground uncommented, you will not see a blue splash screen in the task manager. But if you have commented the code in applicationDidEnterBackground and uncomment the code in applicationWillResignActive, you should see the blue splash screen in the task manager. This is not desirable however. The issue is how to display the splash screen in the applicationDidEnterBackground method.
- (void)applicationWillResignActive:(UIApplication *)application {
//works - but undesirable
//[self addDummyView];
//[_tabBarController.view snapshotViewAfterScreenUpdates:YES];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
//does not work - needs to work to show dummyview only when application actually goes into the background
[self addDummyView];
[_tabBarController.view snapshotViewAfterScreenUpdates:YES];
}
- (void)addDummyView {
UIView *topView = _tabBarController.view;
UIView *colorView = [[UIView alloc] initWithFrame:topView.frame];
[colorView setBackgroundColor:[UIColor blueColor]];
[topView addSubview:colorView];
[topView bringSubviewToFront:colorView];
}
When the applicationDidEnterBackground method returns, a snapshot of the current view of the app is taken to be used for the multitasking view. The reason that you are not seeing the update is because the snapshot is taken before the drawing cycle. Even if you call setNeedsDisplay the snapshot still is taken before.
To wait until the view updates (after you have added your subview) call this:
[self.view snapshotViewAfterScreenUpdates:YES];
with a value of YES. This forces your changes to render first. You can read more about handling stuff like this in apple docs here: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforHandlingAppStateTransitions/StrategiesforHandlingAppStateTransitions.html#//apple_ref/doc/uid/TP40007072-CH8-SW27
You can get you answer here: Show splash screen when application enters background.
Keep your code in applicationWillResignActive.
Your code is fine. You should know that applicationDidEnterBackground is not called when you double tap the home button. It is called when you switch to another app or go to springboard.
So, you should press the home button only once, then double tap it and the screenshot of your app should have the image view. I replicated your use case in a test project and it works for me.
If it still does not work, you should see if the image of the image view is not nil. Oh, and please don't hide the app window.

How to stop iAds from skewing the SKScene in xcode?

So I have added iAds to my application and I have done this very simply. By importing iAds into the ViewController.h and putting the following code into the ViewController.m file:
self.canDisplayBannerAds = YES;
This works, however, when I the add loads the screen is squished. Where all of the images and sprites become shorter.
Is there any way the add can just be overlaid on top of the SKScene? so that is does not affect the elements below – so that it stops the squishing?
Also, is there a way to only have the banner ads run in certain SKScenes or when a BOOL is changed from YES to NO?
UPDATED
Code from my project:
#import "XYZViewController.h"
#import "XYZMenuScene.h"
#import <iAd/iAd.h>
#implementation XYZViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [XYZMenuScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
//iAds Enabled
self.canDisplayBannerAds = YES;
// Present the scene.
[skView presentScene:scene];
}
This is all I have in terms of the iAds. It makes the entire scene push upwards to make room for the ad banner. Where I want it to just be over the scene and not push anything. So it covers, instead of pushes.
To overlay you can set the Z position of the banner higher than the rest of the content by default it's 0.
eg:
banner.layer.zPosition=2;
but I believe the iAd framework has built in method thats you can override to control when the ads must display and when they shouldn't and give you much more control.
Specific methods are called when the ad is available,and like you said you make the ads appear only when a boolean value is 1 or 0.
eg:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if(showADS==1)
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// Assumes the banner view is just off the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
else
{NSlog(#"No ads");}
}
check apple's documentation regarding this,they are really helpful
https://developer.apple.com/library/ios/documentation/userexperience/Conceptual/iAd_Guide/WorkingwithBannerViews/WorkingwithBannerViews.html
But let give a complete example.
The banner instance is only available in you iAd Methods not outside them.
In your view did load method:
- (void)viewDidLoad
{
self.canDisplayBannerAds=YES;
}
This method is called when the ad is loaded,in this method specify the position of the ad
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
banner.layer.zPosition=2;
/*do all the additional like checking is the boolean is 1 or 0 etc.*/
}
If you are working with iAd and sprite kit,you need to call methods in your view controller from the scene class to do all the ad work.
Suppose you have a method named checkAD in your view controller that checks if the ad should shown or not etc..
You can call this method from your scene class by using this code
if([self.delegate respondsToSelector:#selector(checkAD)]){
[self.delegate checkAD];
}
Add the SKSCene in a container View that might help. From my experience any Apple subclasses of UIViewController can do weird stuff when iAds are added through canDisplayBannerAds.

Can't remove Admob Banner from the view (iOS)

I have implemented Admob into my app but i've noticed that if the Admob view doesn't receive an ad, I can't remove it from the superview. If it already has an ad loaded it just stays there with that ad loaded even if the device is not connected to the internet. This is my code:
self.admobBannerView = [[GADBannerView alloc] init];
self.admobBannerView.frame = CGRectMake(0.0,self.view.frame.size.height-50,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height);
self.admobBannerView.adUnitID = #"...";
self.admobBannerView.rootViewController = self;
self.admobBannerView.delegate = self;
[self.view addSubview:self.admobBannerView];
[self.admobBannerView loadRequest:[GADRequest request]];
Then the Admob delegate
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
[self.admobBannerView removeFromSuperview];
}
Despite calling [self.admobBannerView removeFromSuperview]; the banner remains where it is. I can't understand why this is happening. Any help is appreciated.
Thanks
I had the same problem and debugged the view hierarchy w/ Xcode only to find multiple GADBannerViews existed. Fixed the code to check if ad view already existed before adding one.
In your case you should wrap the ad view creation in:
if (self.admobBannerView != nil)
{
// create ad
}

On dismiss view iAds becomes black in ios 5 ipad.(dark black)

I have a tab based application. I have created an iAd object in app delegate class and using it in my three view controller class. It's working good on second tab's screen and third tab's screen. On second tab there is a table view, when clicking the row of that table view i navigate to the new view where i have used the same code for iAd. On clicking the iAd, iAd screen opens in landscape mode and when closing the screen becomes black and log the following.
[ADHostWindowController supportsOrientation:]: message sent to deallocated instance 0x100bc740
I created the object in app delegate like this:
self.bannerView = [[ADBannerView alloc]init];
[self.bannerView setDelegate:self];
I'm adding banner in view controllers like this:
[[[self appdelegate] bannerView] setFrame:CGRectMake(0, hightofView-180, 768, 66)]
All my view controllers are in portrait but iAds always open in landscape mode.
This is working in iOs 6, but not with iOS 5 on iPad. How do I fix this?
My guess your problem is not related to iAds but rather to memory issues.
It seems that an object of class kind ADHostWindowController is being deallocated prematurely.
My advice would be to make sure that ADHostWindowController is not released i.e (retainCount>=1) before supportsOrientation: is called to it. (which is definitely after the iAd opens).
For diagnosis: Try logging the retain count of that ADHostWindowController (then maybe retaining it one more time) before opening an iAd and see what happens.
Take a look at TabbleBanner code in iAd sample from Apple: https://developer.apple.com/library/ios/#samplecode/iAdSuite/Introduction/Intro.html
I don't investigate it in detail, but you need to follow the Apple iAd guide:https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/iAd_Guide/BannerAdvertisements/BannerAdvertisements.html
To create a ADBanner, in each UIViewController, add one to self.view
#property (strong,nonatomic) ADBannerView *bannerView;
- (void)viewDidLoad
{
[super viewDidLoad];
[self createADBanner];
}
- (void)createADBanner{
self.bannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.bannerView setDelegate:self];
[self.view addSubview:self.bannerView];
}
For beginning, you need to modify bannerView size and setCenter if need to place it at top or bottom.
- (void)viewDidLayoutSubviewsj{
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
} else {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
}
}
And do the same when rotate:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
} else {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
}
}

self.addSubView not working on iPad

I have an app that attempts to retrieve an iAd and if is unsuccessful loads an AdMob ad. It works perfectly on iPhone but when run on iPad I get a continuous loop that prevents the app from loading. Here's some code:
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
#try {
NSLog(#"Ad Error, looking for AdMob Ad...");
// Create a view of the standard size at the bottom of the screen.
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
// I know the banner size is incorret for iPad but it's only supposed to run
// on iPad in compatibility mode and changing doesn't help
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = #"XXXXXXX";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
GADRequest *admobRequest = [GADRequest request];
admobRequest.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID,
nil];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest: admobRequest];
[iAdBanner setHidden: YES];
[bannerView_ setHidden: NO];
}
#catch (NSException *e) {
NSLog(#"Exception: %#", e);
}
#finally {
}
}
The NSLog prints out continuously and the app doesn't load.
012-02-24 21:58:38.991 TrophyConverter Free[2948:15e03] Ad Error, looking for AdMob Ad...
2012-02-24 21:58:38.992 TrophyConverter Free[2948:15e03] Ad Error, looking for AdMob Ad...
2012-02-24 21:58:38.994 TrophyConverter Free[2948:15e03] Ad Error, looking for AdMob Ad...
Has anyone else experienced this? How do I over come it? I've managed to use a bool to stop the continuous log printing and load the app but no Ad is shown.
EDIT:
The issue completely disappears when I remove this line
[self.view addSubview:bannerView_];
which isn't helpful since this is the part that adds the AdMob view.
I've also tried changing the build target to be a universal app rather than a iPhone app. This fixes the problem but I don't want it to be a universal app and I have no layouts created for it.
I couldn't find a fix for this in the end so I basically added a bool that was switched once one fail had been made. Then no ad would be added if the check had been done and not already worked.

Resources