Friday 18 November 2011

iAD intergration codes

http://bees4honey.com/blog/tutorial/how-to-add-iad-banner-in-iphoneipad-app/
http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-app
http://developer.apple.com/support/ios/iad-network.html

Code by GauravDS ----------

Step 1 :  Make a view based application and suppose I get name as "iADTest".
Step 2 :  Import iAD.framework from add exiting framework. If u didn't get it on list, click on add other and add it from the path
Macintosh HD/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/Frameworks/iAd.framework
optional if above will not find-
Maybe you can reference it only by adding in the Build Setting -> Other Linker Flags the value -weak_framework and after that entrance add in another row iAD

Step 3 : write below code in files, or if u made a new file which contain .h, .m & .xib file then in that file u have to write this code. Suppose u made a new view based file ABC (.h, .m & .xib) then make a code in


in iADTestViewController.h file (full code is here )
===================
#import <UIKit/UIKit.h>
#import <iAd/ADBannerView.h>




@interface iADTestViewController : UIViewController <ADBannerViewDelegate>{
    ADBannerView *adView,*adView1;
    BOOL bannerIsVisible;
}
@property (nonatomic,assign) BOOL bannerIsVisible;
@property (nonatomic, retain) IBOutlet ADBannerView *adView,*adView1;

@end
============================================================
in iADTestViewController.m file (full code is here )
====================
#import "iADTestViewController.h"

@implementation iADTestViewController
@synthesize bannerIsVisible,adView,adView1;

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    if (!self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
          [UIView commitAnimations];
        self.bannerIsVisible = YES;
    }
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
        [UIView commitAnimations];
        self.bannerIsVisible = NO;
    }
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
-(void)viewDidLoad{
    adView.delegate=self;
    adView1.delegate=self;
    self.bannerIsVisible=NO;
    [super viewDidLoad];
}
- (void)dealloc {
    adView.delegate=nil;
    [adView release];
    adView1.delegate=nil;
    [adView1 release];
    [super dealloc];
}

@end
============================================================
in iADTestViewController.xib file (Open it in interface builde by double click on the project)
drag two iAd that is ADBannerView and open file's owner in Connection Builder (Interface Builder -> Tools -> Connection Builder) then u get two outlet as u mention in the above code as "adView"
and "adView1" to their ADBannerView iAD. see image
=============================================================
Step 4 : Run the project and U see the project as

 

No comments:

Post a Comment