Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-07-2010, 11:32 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default iAd Problem

I built it into my xib and tested it, and it got the deal in simulator that says ads are working properly, but when they reviewed the app it said something to the effect of needing code to hide the view when no ad was displayed. How do I do this?
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 07-07-2010, 11:56 AM   #2 (permalink)
Registered Member
 
Join Date: Dec 2009
Location: Benicia, CA
Age: 50
Posts: 152
That Don Guy is on a distinguished road
Default

I assume your ad has an ADBannerViewDelegate defined in code? When an ad can't be displayed (for example, because your Wi-Fi is turned off), your delegate's bannerView:didFailToReceiveAdWithError: method will be called - set your ADBannerView's hidden property = YES to hide the blank iAd box that would otherwise show up. (Remember to set it back to NO when ads are available again, presumably in the delegate's bannerViewDidLoadAd: method.)

I also like to have a separate UIImageView of the same size as the banner ad in the same location, initially hidden, but whenever the banner ad is hidden, I show the image (that way, there's something in the space where the banner ad would be).

-- Don
That Don Guy is offline   Reply With Quote
Old 07-07-2010, 12:12 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default

I actually don't have anything in code. They sent a snipped with the failedtoload code but when I copy that into my .m file I get Errors when I try to build.

Code:
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
    NSLog(@"Banner view is beginning an ad action");
    BOOL shouldExecuteAction = [self allowActionToRun]; // your application implements this method
    if (!willLeave && shouldExecuteAction)
    {
        // insert code here to suspend any services that might conflict with the advertisement
    }
    return shouldExecuteAction;
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    if (!self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
		// assumes the banner view is offset 50 pixels so that it is not visible.
        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];
		// assumes the banner view is at the top of the screen.
        banner.frame = CGRectOffset(banner.frame, 0, -50);
        [UIView commitAnimations];
        self.bannerIsVisible = NO;
    }
}
That's what I put in my .m file. Do I need to declare anything in my .h? Errors like expected ')' before AdBannerview etc.
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 07-07-2010, 12:27 PM   #4 (permalink)
Registered Member
 
suksmo's Avatar
 
Join Date: Mar 2010
Location: iTunes store : Scrambleface otherwise Scotland
Posts: 262
suksmo is on a distinguished road
Default

Best thing to do here is download the 'how to implement iad video from wwdc. It's free and when you watch it you will see a really perfect implementation of iad. Dissapears when not filled, rises up when filled. It's only fifty odd mins long. You'll thank me!

Oh and if you want to see how that works in an app look at mines. Feel free to click about
__________________
FREE live action video puzzler

download it FREE now:-
http://itunes.apple.com/us/app/scram...416999968?mt=8
suksmo is offline   Reply With Quote
Old 07-07-2010, 01:05 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default

Thanks. I'll check it out.
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 07-07-2010, 01:35 PM   #6 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default

i cant find that video do u have a link
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 07-07-2010, 08:14 PM   #7 (permalink)
Registered Member
 
Join Date: Dec 2009
Location: Benicia, CA
Age: 50
Posts: 152
That Don Guy is on a distinguished road
Default

Here's how I did it - there are a few hoops you have to jump through.

First, you need to add the iAd.framework - in XCode, in the Overview column, control-click on "Frameworks", and in the menu that pops up, move your cursor over "Add", then click on "Existing Frameworks"; click on "iAd.framework". It should now appear below Frameworks in the Overview (along with, presumably, UIKit, Foundation, and CoreGraphics).

Next, make some changes to your main app view controller's .h file:
add an import for <iAd/iAd.h>, add <ADBannerViewDelegate> to the @interface line, and declare an IBOutlet ADBannerView (you will need this to hide/move the Ad Banner in Interface Builder).

Here is an example, assuming your project is named yourApp:
Code:
#import <iAd/iAd.h>

@interface yourAppViewController : UIViewController <ADBannerViewDelegate>
{
	IBOutlet ADBannerView *theAdBanner;
}
Next, in your view controller's .m file, add code for the three methods that can be called.

bannerViewActionShouldBegin is called when the app wants to show a full-size ad; if you want to pause your app while the ad is running, you do it here. (Also, if, for some reason, you do not want the ad to display, return NO.) My sample code does nothing other than return YES as my app does not really do anything in the background.
Code:
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
    if (!willLeave)
    {
        // insert code here to suspend any services that might conflict with the advertisement
    }
    return YES;
}
bannerView:didFailToReceiveAdWithError: is called when an ad cannot be put into the banner for some reason - for example, your WiFi is turned off. In this case, the iAd banner box will remain on the screen but be empty, unless you do something to hide it. This is why your app was rejected - you just let the box sit there. The sample code you had moves it 50 pixels up (which would put it off the top of the screen if it was placed at the top). My code just hides it.
Code:
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
	theAdBanner.hidden = YES;
}
bannerViewDidLoadAd is called when an ad is actually put into the banner. I use it to restore the banner if it is hidden.
Code:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
	theAdBanner.hidden = NO;
}
Note that I do not use a variable like the Apple sample code's bannerIsVisible, because I just hide and unhide the banner rather than doing anything fancy. If you want to use a separate variable (so you could move the banner off and on the screen, the way the Apple sample code does), you declare the variable (as a bool) in your class definition in the .h file, and initialize it to YES (since it starts on the screen) in viewDidLoad.
What the code you got does is, in bannerViewDidLoadAd, it checks to see if it is off the screen (by seeing if the variable = NO), and if it is, it changes the banner's Y-coordinate to put it onto the screen, then sets the variable to YES; and, in didFailToReceiveAdWithError, it does the opposite - it checks the variable to see if the banner is on the screen, and if it is, it changes the banner's Y-coordinate to move it off the screen and sets the variable to NO.

-- Don
That Don Guy is offline   Reply With Quote
Old 07-08-2010, 01:53 AM   #8 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 8
Spyder9 is on a distinguished road
Default

Watch the wwdc video, but essentially, you have to call hide ad banner in your viewDidLoad and didFailToReceiveAdWithError


- (void)bannerViewADBannerView *)banner didFailToReceiveAdWithErrorNSError *)error
{
[self hideAdBanner];
}

-(void) viewDidLoad
{
[self hideAdBanner];
}
Spyder9 is offline   Reply With Quote
Old 07-08-2010, 09:22 AM   #9 (permalink)
Registered Member
 
Join Date: Dec 2009
Location: Benicia, CA
Age: 50
Posts: 152
That Don Guy is on a distinguished road
Default

Quote:
Originally Posted by Spyder9 View Post
Watch the wwdc video, but essentially, you have to call hide ad banner in your viewDidLoad and didFailToReceiveAdWithError

Code:
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error 
{
     [self hideAdBanner];
}

-(void) viewDidLoad
{
     [self hideAdBanner];
}
"hideAdBanner" is something you have to write yourself - it's not part of ADBannerView or ADBannerViewDelegate that hides the ad banner for you - but you would use the code that is in didFailToReceiveAdWithError. In other words, something like:
Code:
-(void) hideAdBanner
{
    theAdBanner.hidden = YES;
}
-- Don
That Don Guy is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 331
9 members and 322 guests
bignoggins, Chickenrig, firecall, givensur, iNet, michaelhansen, Objective Zero, PlutoPrime, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,893
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:33 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0