Not seeing the "Connected to iAd" popups on my app - ios

I am in the process of making an iOS app (Objective-C), I am nearing the end of my production of the application itself and now I am trying to implements Interstitial Ads. I was before seeing the Blue You are connected to iAd banners before on my app but I do not seem to see them now. My test device (iPhone 5S, iOS 9.2.1) is connected to the internet, so that is not the issue and the account I am using is a free developer account, not a paid one.
Below is code from one of my view controllers (the code is identical on all three of them with regard to iAd), I got the code from Apple's test project and modified it slightly.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self cycleInterstitial];
// Other non-relavent stuff
}
- (void)like: (UIButton*)button {
// Other non-relavent stuff
NSInteger i = arc4random_uniform(3);
if (i == 2) {
[self presentInterlude];
}
}
- (void)cycleInterstitial {
// Clean up the old interstitial...
NSLog(#"Cycling");
self.inter.delegate = nil;
// and create a new interstitial. We set the delegate so that we can be notified of when
self.inter = [[ADInterstitialAd alloc] init];
self.inter.delegate = self;
}
- (void)presentInterlude {
// If the interstitial managed to load, then we'll present it now.
if (self.inter.loaded) {
NSLog(#"Requesting the ad");
[self requestInterstitialAdPresentation];
}
}
- (void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd {
[self cycleInterstitial];
}
- (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error {
[self cycleInterstitial];
}
I know it is not my random number as I removed that previously. Any ideas on why my ads are not showing up? Could it be my code, my non-paid developer account, or is it something else?
I am not trying to display an actual ad I am only trying to get that You are connected to iAd popup to display to confirm that my implementation is working, so it should not be the fact that I am using a non-paid developer account.

Related

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
}

Test iAds are good, but live iAds fail

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.

Game Center Sandbox mode display multiple leaderboards

I'm preparing to launch my first app and want to have multiple leaderboards inside my game. Currently in sandbox mode I can track and log scores into Game Center successfully. Game Center saves my scores (only if it is higher) and seems to be fully functional.
I know through Itunes Connect we have the ability to set up multiple leaderboards and it seems pretty straight forward. I still want to be able to test multiple leaderboards before publishing my game though. Is there a way to do this in sandbox mode? Currently it seems like my scores are only automatically logged into a default leaderboard. Below is the relevant code I'm using to save/access scores. Thanks!
ABGameKitHelper.m
#pragma mark - Leaderboard
-(void) reportScore:(long long)aScore forLeaderboard:(NSString*)leaderboardId
{
GKScore *score = [[GKScore alloc] initWithCategory:leaderboardId];
score.value = aScore;
[score reportScoreWithCompletionHandler:^(NSError *error) {
if (!error)
{
if(![self hasConnectivity])
{
[self cacheScore:score];
}
if (ABGAMEKITHELPER_LOGGING) NSLog(#"ABGameKitHelper: Reported score (%lli) to %# successfully.", score.value, leaderboardId);
}
else
{
[self cacheScore:score];
if (ABGAMEKITHELPER_LOGGING) NSLog(#"ABGameKitHelper: ERROR -> Reporting score (%lli) to %# failed, caching...", score.value, leaderboardId);
}
}];
}
-(void) showLeaderboard:(NSString*)leaderboardId
{
GKLeaderboardViewController *viewController = [GKLeaderboardViewController new];
viewController.leaderboardDelegate = self;
if (leaderboardId)
{
viewController.category = leaderboardId;
CCLOG(#"Going to category already created");
}
[[self topViewController] presentViewController:viewController animated:YES completion:nil];
}
MainScene.m
- (void)gameCenter {
[[ABGameKitHelper sharedHelper] reportScore:1400 forLeaderboard:#"Score"];
[[ABGameKitHelper sharedHelper] showLeaderboard:#"Score"];
}
I'm not sure if I understand your question properly, but I'll try to answer! Game Center does support multiple leaderboards:
-If you want to send a score to specific leaderboard, you just have to call the function [[ABGameKitHelper sharedHelper] reportScore:X forLeaderboard:LEADERBOARD_ID];, where X represents the score you'd like to send, and LEADERBOARD_ID is the ID of the leaderboard you want to send the score to, as specified in iTunes Connect.
-When you have multiple leaderboards, if you don't want to show just one leaderboard, but a list of them all, you should use the GKGameCenterViewController class instead. However, be careful; this ViewController has been added in iOS 6 only, so you must check which version the device is running. I am also using the ABGameKitHelper, so I've made a function to show this kind of view. Here it goes :
ABGameKitHelper.m
- (void) showGameCenter{
if (![[ABGameKitHelper sharedHelper] hasConnectivity]) return;
//Check if device runs on iOS 5
if([[[UIDevice currentDevice]systemVersion]intValue]==5)
{
//If so, we must use the GKLeaderboardViewController
GKLeaderboardViewController *leaderboard = [[GKLeaderboardViewController alloc] init];
if (leaderboard != nil)
{
leaderboard.leaderboardDelegate = self;
[[self topViewController] presentViewController:leaderboard animated:YES completion:nil];
}
}else if ([[[UIDevice currentDevice]systemVersion]intValue]>=6)
{
//if it runs on iOS 6 or higher, we use GKGameCenterViewController
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil)
{
gameCenterController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateDefault;
[[self topViewController] presentViewController:gameCenterController animated:YES completion:nil];
}
}
}
And don't forget to add :
- (void) gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController{
[gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
}
Using this function will allow you to show a nice view containing all your leaderboards and achievements.
Hope this helps!

How to display Full Screen iad for ipad

I just recently read that full screen iAd only works on iPad. ADInterstitialAd This Class To Use Developing Full Screen iAd. How To Implement Delegate Methodes in ADInterstitialAdDelegate?
You can use this for creating Full screen iAd
in .H file
Import
#import <iAd/iAd.h>
#interface ViewController : UIViewController<ADInterstitialAdDelegate>
{
ADInterstitialAd *interstitial;
}
in. M file
#interface ViewController ()
// Interstitials
- (void)cycleInterstitial;
#implementation ViewController
- (void)cycleInterstitial
{
// Clean up the old interstitial...
interstitial.delegate = nil;
// and create a new interstitial. We set the delegate so that we can be notified of when
interstitial = [[ADInterstitialAd alloc] init];
interstitial.delegate = self;
}
#pragma mark ADInterstitialViewDelegate methods
// When this method is invoked, the application should remove the view from the screen and tear it down.
// The content will be unloaded shortly after this method is called and no new content will be loaded in that view.
// This may occur either when the user dismisses the interstitial view via the dismiss button or
// if the content in the view has expired.
- (void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd
{
[self cycleInterstitial];
}
// This method will be invoked when an error has occurred attempting to get advertisement content.
// The ADError enum lists the possible error codes.
- (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error
{
[self cycleInterstitial];
}
// if you want to show iAd while pushing view controller just use
- (IBAction)onSearchClick:(id)sender {
if (interstitial.loaded) {
// [interstitial presentFromViewController:self]; // deprecated in iOS 6.
[self requestInterstitialAdPresentation]; // it will load iAD Full screen mode.
}
// do whatever you want to do.
}
Have a happy coding. Cheers.

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