iAd - not working properly - iphone

I'm adding iAd on my app.... I managed to have the banner sliding from the bottom (just above my tab bar, 0, 410 i guess)... but only when i launch the app the first time. when then i try to switch the wifi off on my testing device to check if i get the blank banner i get the following message:ADBannerView: WARNING A banner view (0x1b11d0) has an ad but may be obscured. This message is only printed once per banner view. Can please somebody help me??
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animatedAdBannerOn" context:NULL];
NSLog(#"there are ads to show");
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
//----hide banner if can't load ad.
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animatedAdBannerOff" context:NULL];
NSLog(#"sorry, no ads ");
banner.frame = CGRectOffset(banner.frame, 0, 410);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
aBanner = [[ADBannerView alloc]initWithFrame:CGRectZero];
aBanner.frame = CGRectOffset(aBanner.frame, 0, 410);
aBanner.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
aBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:aBanner];
aBanner.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];
I know something is wrong in the CGRectOffset but I'm not able to figure it out.
thanks

FIND THE PROBLEM.... WAS JUST A SIMPLE "!" HERE THE CODE FIXED:
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animatedAdBannerOn" context:NULL];
NSLog(#"there are ads to show");
banner.frame = CGRectOffset(banner.frame,0, -banner.frame.size.height);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
//----hide banner if can't load ad.
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
if (self.bannerIsVisible) { //THE PROBLEM WAS HERE!!!!
[UIView beginAnimations:#"animatedAdBannerOff" context:NULL];
NSLog(#"sorry, no ads ");
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
aBanner = [[ADBannerView alloc]initWithFrame:CGRectZero];
aBanner.frame = CGRectOffset(aBanner.frame, 0, 410);
aBanner.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
aBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:aBanner];
aBanner.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];

Related

iAd Banner not working

SO I used a tutorial to create an iAd Banner at the bottom of the screen and animate it into and out of the window, however the app is a tab based, and i do not quite know the correct offset, so you could tell me I would appreciate it, however the primary problem, is that the adBanner does not always appear, and when it does sometimes it is just a white box. Here is my code.
In my .h
#interface section3 <ADBannerViewDelegate>{
ADBannerView *adView;
BOOL bannerIsVisible;
}
#property (nonatomic, assign) BOOL bannerIsVisible;
//in the .m in the view did load
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0.0, 410.0f);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adView];
adView.delegate = self;
self.bannerIsVisible = NO;
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0.0, -50.0f);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
if (self.bannerIsVisible) {
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0.0, 50.0f);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
I am using Xcode 4.2.1
Thank you very much, any help would be appreciated :)
The tabbar is 44px high so u must add to one of the "50" 44 and make 410 to the full screen size of 3.5 inch means to 480 default. That should be the solution.

iAds not hiding

I have IBOutlet on bottom of the screen for ADBannerView, and I won't to hide it when it shows white screen (not able to load an Ad).
I have this code, but it is not working:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[UIView beginAnimations:#"showAd" context:nil];
CGRect adBannerViewFrame = [bannerView frame];
adBannerViewFrame.origin.x = 160;
adBannerViewFrame.origin.y = 523;
bannerView.frame = adBannerViewFrame;
[UIView commitAnimations];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView beginAnimations:#"hideAd" context:nil];
CGRect adBannerViewFrame = [bannerView frame];
adBannerViewFrame.origin.x = 0;
adBannerViewFrame.origin.y = 0;
bannerView.frame = adBannerViewFrame;
[UIView commitAnimations];
}
Can you help me please, I'm struggling with it for past two hours... :/
you should try something like this (this is from a live project). the iAd banner is at the bottom of the screen and it goes down when it becomes invisible, and it comes up back when it must be visible.
the _isiADBannerVisible is just a simple Boolean variable.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
if (_isiADBannerVisible == false) {
_isiADBannerVisible = true;
[UIView animateWithDuration:0.5f delay:0.f options:UIViewAnimationCurveEaseInOut animations:^{
[banner setFrame:CGRectOffset(banner.frame, 0.f, -50.f)];
} completion:nil];
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
if (_isiADBannerVisible == true) {
_isiADBannerVisible = false;
[UIView animateWithDuration:0.5f delay:0.f options:UIViewAnimationCurveEaseInOut animations:^{
[banner setFrame:CGRectOffset(banner.frame, 0.f, +50.f)];
} completion:nil];
}
}

xcode 4.3 - storyboard - iAd keeps moving

I have added iAd to my iphone app to be at the top of my app. originally I place it at x=0 and y=-50 so that it comes from off the screen. I use the following code for it in my .m :
- (void)bannerView:(ADBannerView *)abanner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[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];
self.bannerIsVisible = NO;
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)abanner
{
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;
}
}
When my app launch iAd get displayed at the top without any problem. but when I open another app and come back to it (without killing it so my app is running in the background) the banner moves another 50 pixel down
any idea?
You are adding 50.0px to banner.frame.origin.y in both cases.
Anyway: even if you'd be substracting 50.px in didFailToReceiveAdWithError: it
could happen that didFailToReceiveAdWithError: would get called multiple times in a
row and your code could move the banner higher and higher up (-50.0,-100.0,-150.0...).
So it's better to hardcode the hidden & visible positions instead of calculating it.
Try this:
- (void)bannerView:(ADBannerView *)abanner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
banner.frame = CGRectMake(0.0,-50.0,banner.frame.size.width,banner.frame.size.height);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)abanner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
banner.frame = CGRectMake(0.0,0.0,banner.frame.size.width,banner.frame.size.height);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}

dismissModalViewController with iAds. A banner view has an ad but may be obscured

Heres my issue. I have a login screen which is shown using PresentModalViewAnimated. Once the user logins in it is dismissed.
On the login screen i have a iAd but when it is dismissed I get this error.
ADBannerView: WARNING A banner view (0x5a37df0) has an ad but may be
obscured. This message is only printed once per banner view
Also when I login then log back out, the iAd is not displayed again.
Snippets of my code
#synthesize bannerIsVisible;
- (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];
}
- (void)viewDidLoad
{
interestingTags = [[NSSet alloc] initWithObjects: INTERESTING_TAG_NAMES2]; //set interestingTag var to define
self.userArray = [[NSMutableArray alloc] init]; //init the userArray
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adView];
adView.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
I think that with this you could to eliminate the error. Just removing the banner view in ViewWillDisappear:
-(void)viewWillDisappear:(BOOL)animated
{
[bannerView removeFromSuperview];
}

Hide iAds on iPhone when there is no network connection

I am trying to include iAds in my app. It works fine when there is network connection but the iAds doesn't hide when the network is not available..please find the code below and help me..thanks for your time..
I included this code in viewDidLoad
static NSString * const kADBannerViewClass = #"ADBannerView";
if (NSClassFromString(kADBannerViewClass) != nil) {
if (self.adView == nil) {
self.adView = [[[ADBannerView alloc] init] autorelease];
self.adView.delegate = self;
self.adView.frame = CGRectMake(0,355,320,60);
self.adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
}
}
[self.view addSubview:self.adView];
Delegate methods:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible) {
[UIView beginAnimations:nil context:NULL];
banner.frame = CGRectOffset(banner.frame, 0,10);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible) {
[UIView beginAnimations:nil context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -10);
[UIView commitAnimations];
self.bannerIsVisible = NO;
NSLog(#"%#",error);
}
}
If I understand your code correctly, you are initially showing the banner. That is not correct. It is better to initially move the banner off-screen and then only move it on-screen when you receive bannerViewDidLoadAd: and back off-screen when you receive bannerView:didFailToReceiveAdWithError:.
This also has the advantage that your banner view does not initially show up empty. Which can happen if there is a slow network connection.
You can do like this
Hide banner during viewdidload and write this in .m file.
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(#"Error loading iAd");
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
NSLog(#"Ad loaded");
self.banner.hidden = NO;
}
-(void)bannerViewWillLoadAd:(ADBannerView *)banner{
NSLog(#"Ad will load");
self.banner.hidden = NO;
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner{
NSLog(#"Ad did finish");
self.banner.hidden = NO;
}