iAd not showing banner ads - iphone

I am building an app in which I want to us iAd banners. the viewcontroller in which I want to show the ad is a UIViewController. I am using storyboards. I implemented the iAd banner exactly as apple shows/demonstrates here:
add iAd framework
import "<iAd/iAd.h>" header
inserted self.canDisplayBannerAds = YES;
but when I run my app, no iAd is showing up. do I forget something? Thank you so much in advance

I had a bit different issue, but the answer fits to your question as well. I updated my old xib file (was from XCode 5.1) to use Size Classes in XCode 6.0. After the update ads showed only in iPhone 4 - 5 and 5s. iPhone 6 and iPhone 6 Plus was without banners (simulators showed the same results as the external devices). When using xib file and using
self.canDisplayBannerAds = YES;
in my situation I moved this command from viewDidLoad to viewDidAppear and banner showed up. Now I can see banners in all devices.

In your .h :
#interface MyViewController : UIViewController <ADBannerViewDelegate>
Add a banner view in your xib file and link this banner view with an IBOutlet
#property (nonatomic, strong) IBOutlet ADBannerView *iAdBannerView;
add the following code to display your ad :
#pragma mark - ADBannerViewDelegate
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(#"banner loaded");
// Display BannerView
_iAdBannerView.hidden = NO;
[UIView animateWithDuration:0.4f
animations:^{
_iAdBannerView.alpha = 1.0f;
}];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
// Print error
NSLog(#"error banner failed :\n%#", error);
// Hide BannerView
[UIView animateWithDuration:0.4f
animations:^{
_iAdBannerView.alpha = 0.0f;
} completion:^(BOOL finished) {
_iAdBannerView.hidden = YES;
}];
}
and normally your adbanner will appear when you receive and ad and disappear otherwise.

The problem was that I had to sign the iAd contract in itunes connect, which I had not done yet. it works fine now!

Related

IOS7 Xcode 5 universal app won't rotate on iphone, but will on ipad

I have and app that was initially built for ipad and i'm in the midst of making it a universal app. I've got the entire app working, universally, all functionality is working and sized correctly. Except that on the iphone the app won't rotate in any direction, it stays in portrait mode.
Here's what i've got:
Checked the iPhone Device Orientation from the Targets/General section: (Portrait, Landscape Left and Landscape Right) are all checked
In my Main_iPhone.storyboard i have a root view controller attached to a uinavigation controller that pops a settings (uitableview) upon the first load of the app. (same as the ipad story board but sized for iphone)
the view controller programatically loads a xib: TakePhotoView.xib to a cameraOverlayView which has a label on it to tell the user to touch the screen to take a picture.
Again, this works perfect on the ipad and i'm very new to ios development. i Actually had a friend develop the ipad app and i;m using it as my step-off point to dig into ios, thus i'm trying to turn it into a universal app to get my feet wet.
Any pointers would be much appreciated. I'm pulling my hair out with this.
(BOOL) shouldAutorotate{
return YES;
}
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeRight; //you can choose either landscape orientation here
}
Finally got this figured out. It was the UIImagePickerController. For some reason it worked perfect for the ipad but i needed to overwrite it for the iphone.
#import "UIImagePickerController+rotation.h"
#interface UIImagePickerController (private)
- (BOOL)shouldAutorotate;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
- (NSUInteger)supportedInterfaceOrientations;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
#end
#implementation UIImagePickerController (Private)
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotate {
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
return UIInterfaceOrientationPortrait;
}
else
{
return UIInterfaceOrientationLandscapeRight;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#end

iAd in sprite kit game

I know there is at least one question asking how to integrate iAd into a sprite kit game, but that is not what I am looking for. I am looking for a portrait version of how to do it. There seem to be absolutely 0 tutorials online as to how to do this, so I came here. Can someone please tell me how to simply enable iAd in a Sprite Kit game? I have enabled canDisplayBannerAds and have used the originalContentView property for my UIView, but I keep getting a crash that says
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController originalContentView]: unrecognized selector sent to instance 0x10a0a7410'
any help would be appreciated, and here is my code in my view controller
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.originalContentView;
//skView.showsFPS = YES;
//skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
self.canDisplayBannerAds = YES;
// Present the scene.
[skView presentScene:scene];
}
For those that don't understand, and those that are for future references, here is how I did this to my Sprite Kit game.
I had my game project created using the SpriteKit template in Xcode, then went to the project settings as so:
In the "Link Binary With Libraries" section, just make sure to hit the + button, and add the iAd framework.
After doing that, go to your view controller for your Sprite Kit game, and then type this:
// at the top
#import <iAd/iAd.h>
// do this in .m, above #implementation
#interface YourViewControllerClassName ()
#property (nonatomic, strong) ADBannerView *banner;
#end
// after the implementation line
// if you're needing to do it horizontally, do:
- (void) viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.banner = [[ADBannerView alloc] initWithFrame:CGRectZero];
self.banner.delegate = self;
[self.banner sizeToFit];
self.canDisplayBannerAds = YES;
SKView *view = (SKView *)self.originalContentView;
SKScene *scene = [[YourScene alloc] initWithSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)];
[view presentScene:scene];
}
If you're doing the iAd in just a normal, portrait, you can do the above code, but you can also just use - (void) viewDidLoad instead...
Now is the delegate methods for the iAd to appear...
Go to the code above the #implementation line, and edit it
// do this in .m, above #implementation
#interface YourViewControllerClassName () <ADBannerViewDelegate>
#property (nonatomic, strong) ADBannerView *banner;
#end
Now, go under the implementation line, and enter this:
// NOTE: THIS CODE CAME FROM APPLE MOSTLY
// I DID EDIT IT, BUT THE CREDIT GOES TO APPLE'S DOCUMENTATION
// ON IAD
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (banner.isBannerLoaded) {
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// Assumes the banner view is placed at the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!banner.isBannerLoaded) {
[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];
}
}
That is all that is required from the iAd to actually work in a SpriteKit game. I hope that I helped those that are going to read this.

How to add iAd in app

I want to add iAd in my app. And i have done lot of research and seen video that display how to add iAd in your project. But all video and tutorial display code for adding iAd in project none of them said any thing about if we have to do something in iTunes connect or not.
I have seen this link in apple doc. which is nice to add iAd. and in that link it will display tab iTunes Connect Developer Guide which display some setting we do have to make in iTunes connect to add iAd in app.
So as my understanding we have to first do that setting in iTunes connect account for iAd and then implement code to add iAd in project.
But i m confuse at this line in apple doc After you have enabled at least one app for iAd ads, you see the iAd Network module on your iTunes Connect homepage. What does it mean that enable app for iAd?
itunesconnect -> manage your apps
and this code Display the Default Screen of iAd network
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
#interface iAdExViewController : UIViewController <ADBannerViewDelegate>
{
ADBannerView *adView;
BOOL bannerIsVisible;
}
#property (nonatomic,assign) BOOL bannerIsVisible;
#end
Then modify viewDidLoad method in iAdExViewController.m
- (void)viewDidLoad
{
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
[self.view addSubview:adView];
adView.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
NSLog(#"Banner view is beginning an ad action");
BOOL shouldExecuteAction = YES;
if (!willLeave && shouldExecuteAction)
{
// stop all interactive processes in the app
// [video pause];
// [audio pause];
}
return shouldExecuteAction;
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
// resume everything you've stopped
// [video resume];
// [audio resume];
}
Go to itunes connect -> manage your apps and pick the app you want, then click on Set Up iAd Network, just that.
But i m confuse at this line in apple doc After you have enabled at least one app for iAd ads, you see the iAd Network module on your iTunes Connect homepage. What does it mean that enable app for iAd?
This means, when you activate iAd (as I told you), a new module appears called iAd Network, and there you can see the statistics (impresions, revenue, etc)

iAd doesn't hide when it fails to load?

This seems like the dumbest question ever, but after wading through all of Apple's documentation and the useless online tutorials, I still can't figure out how to properly implement iAds into my application. So, my app starts off in a table view controller, and I have an iAd object underneath the navigation bar and above the table.
Now, in my code: (I also have the iAd framework added)
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
#interface MasterTableViewController : UITableViewController <ADBannerViewDelegate>
{
IBOutlet ADBannerView *iAd;
}
#property(nonatomic, readonly, getter=isBannerLoaded) BOOL bannerLoaded;
#end
then in the .m file
#import "MasterTableViewController.h"
#interface MasterTableViewController ()
#end
#implementation MasterTableViewController
#synthesize bannerLoaded;
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
if (!willLeave)
{
// nothing in this case thanks to ARC
}
return YES;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
iAd.hidden = NO;
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
iAd.hidden = YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
for (int i = 0; i > 0; i++)
{
if (bannerLoaded)
{
iAd.hidden = NO;
}
else
{
iAd.hidden = YES;
}
}
}
Now, the problem is, when I test the app without internet connection the iAd does not load (obviously) BUT it also does not hide. So, at the top of the screen I'm left with a big white rectangle. Otherwise, the ad works fine when a connection is available. Does anyone have any ideas? Also - I just added the endless loops to see if they made a difference, those were completely on purpose lol.
I'm assuming you have added your ADBannerView via the Storyboard as I can't see where you initialise the banner position.
In storyboard, set the initial location just off screen.
In "bannerViewDidLoadAd", animate the banner into view.
In "bannerView: didFailToReceiveAdWithError:", animate the banner out of view.
There is a good example here https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/iAd_Guide/WorkingwithBannerViews/WorkingwithBannerViews.html
Hope this helps. I have just implemented this but don't have access to my code at the moment.
It does bring up some errors in the simulator but works fine on a device.
I have tested this on iOS6 and works ok even if an iAd is displayed then the user loses the connection (so it looks like "bannerView: didFailToReceiveAdWithError:" is being called for me).
You have a property bannerLoaded for saving the state of your Ad, which is good.
At the very first, in your viewDidLoad method, iAd can't be loaded, so you have to set your property accordingly : self.bannerLoaded = NO;
Then, when you receive / fail to receive your ad, you need to update this property.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerLoaded) {
iAd.hidden = NO;
self.bannerLoaded = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerLoaded) {
iAd.hidden = YES;
self.bannerLoaded = NO;
}
}

how to implement AdBannerview and ADBannerview delegate

I am having trouble implementing ADBannerView and its delegate protocol.
I implemented the following code in my view class (also made the view conform to the ADBannerViewDelegate protocol):
//add iAds
ADBannerView *adView = [[ADBannerView alloc] initWithFrame: CGRectMake(0, 318, 320, 50)];
adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];
adView.delegate = self;
//adView.delegate = ADBannerViewDelegate;
[self.view addSubview: adView];
then I created a class for the ADBannerViewDelegate, with the following .m
//
// ADBannerViewDelegate.m
//
#import "ADBannerViewDelegate.h"
#implementation ADBannerViewDelegate
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(#"bannerview did not receive any banner due to %#", error);}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner{NSLog(#"bannerview was selected");}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{return willLeave;}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {NSLog(#"banner was loaded");}
#end
the banners are eventually presented but the console keep throwing the following type of errors:
2011-02-27 15:00:54.108 app[31639:207] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=5 "The operation couldn’t be completed. Banner view is visible but does not have content" UserInfo=0x6356a40 {ADInternalErrorCode=5, NSLocalizedFailureReason=Banner view is visible but does not have content}
and the delegate functions are not doing anything , so no NSLog at all. Obviously not catching the errors.
I am stumped. I guess I am missing something in the linkage of the Adbanner view calls in the view and the delegate. Not sure how to do it or what is wrong.
Any help? Thanks in advance.
Jason
The reason why is you told the AdBannerView that you are its delegate but you never put it in your implementation file. Your implementation file should look like this (notice the line with #implmentation):
//
// ADBannerViewDelegate.m
//
#import "ADBannerViewDelegate.h"
#implementation ADBannerViewDelegate<ADBannerViewDelegate>
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(#"bannerview did not receive any banner due to %#", error);}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner{NSLog(#"bannerview was selected");}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{return willLeave;}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {NSLog(#"banner was loaded");}
#end
And also you shouldn't name your class ADBannerViewDelegate. Your class should be a delegate (respond to it) to ADBannerView but not be named after it.
i successfully integrated iAds in my app using this tutorial:
http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-app
might help you too.
You don't try to implement a class named ADBannerViewDelegate, you put those methods in the implementation for your view class.
(If you actually named your view class "ADBannerViewDelegate", don't. It's confusing.)
For me it was the target and the device, I ran it on the 4.3 simulator and my ipad 2 but the app was for iphone 5.1, when I changed the target all went swimmingly
you can Use this link its very helpful
http://codewithchris.com/iad-tutorial/