Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

iAd coding?? Helpp

ChessinChessin Posts: 595Banned Members
edited July 2010 in iOS SDK Development
I am trying to set up iad in my app. I am trying to use the guide on developer.apple.com for the declaring of the banner view but it isnt clear what to do. Can someone please give me a code to declare the banner view in my app? Also if you could how do you hide the banner view when there is no ads being served? Are those the only 2 events i need for iads or do I need more. HELLLPPPP:confused::confused::(:(
Post edited by Chessin on

Replies

  • That Don GuyThat Don Guy Posts: 154Registered Users
    edited July 2010
    First, you need to add the iAd framework. To do this, control-click (i.e. hold down the control key while clicking the mouse - if you have a two-button mouse, clicking with the right button might work as well) on "Frameworks" in the Groups & Files list on the left side of the XCode window, then move your mouse over "Add", then click on "Existing Frameworks", then select iAd.framework.

    Second, add the following to your main view controller's .h file:
    #import <iAd/iAd.h>
    
    @interface iAdTestViewController : UIViewController <ADBannerViewDelegate> {
    	IBOutlet ADBannerView *theAdBanner;
    }
    
    This example assumes the project is called iAdTest - replace iAdTestViewController with the name of your main view controller.

    Third, you need to go into Interface Builder to connect the AdBannerView you have there with the AdBannerView variable you just defined. (Make sure to save the changes you made to the .h file before starting IB.)
    Select the AdBannerView, then click on the second button at the top of the Inspector window (the one with a right-pointing arrow inside a blue circle).
    Click and drag from the circle next to where it says "Delegate" to the "File's
    Owner" icon in the main XIB window. Do the same from the circle next to where it says "New Referencing Outlet", but this time, when you reach the File's Owner icon, a small popup should appear; click on "theAdBanner" (or whatever name you gave to the ADBannerView variable - do not click on "view"). Save and exit IB.

    Fourth, you need to implement three methods defined in the ADBannerViewDelegate protocol.

    bannerViewActionShouldBegin is called when somebody touches the ad
    banner and a full-screen ad is about to appear. If the willLeaveApplication
    parameter is NO, then the ad will cover your app, but your app will keep running (if it is YES, your app moves to the background), so if it is NO, you may need to do something (for example, pause the application, or turn off sounds); this is where you do it. The method returns YES if you want the ad to show, and NO if you do not.
    In this case, all it does is return YES.
    - (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
    {
        if (!willLeave)
        {
            // insert code here to suspend any services that might conflict with the advertisement
        }
        return YES;
    }
    
    didFailToReceiveAdWithError is called when an ad banner cannot be loaded
    for whatever reason - for example, your WiFi is turned off. When this happens, you need to hide the ad banner; otherwise, a blank iAd frame appears, and your application will be rejected when submitted.
    In this code, the ad banner is hidden by setting its hidden property to YES.
    This has the added benefit that you do not have to check to see whether or not it is hidden before you hide it.
    - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
    {
    	theAdBanner.hidden = YES;
    }
    
    bannerViewDidLoadAd is called when an ad is loaded into a banner.
    If the banner is hidden, you want to display it.
    In this code, the ad banner's hidden property is set to NO.
    - (void)bannerViewDidLoadAd:(ADBannerView *)banner
    {
    	theAdBanner.hidden = NO;
    }
    
    There is one other thing you might want to do, although I am not 100% sure about this one. There might be a problem where, if you have Airplane Mode turned on when you start the app, the didFailToReceiveAdWithError method might not be called, but you would still get an empty iAd frame (and, like I said, if the Apple reviewers see this, it is an automatic rejection). To solve this, make sure your ADBanner begins in "hidden" mode. You can do this by setting it to hidden in IB, or (what I do) set the hidden property = YES in viewDidLoad.

    -- Don
Sign In or Register to comment.