Friday 4 May 2012

How to integrate AdMob in you iPhone/iPad application:

How to integrate AdMob in you iPhone/iPad application:


This is the AdMob example. In this example you will see hou you can integrate AdMob in your iPhone application.

Step 1: Open Xcode, Create a new project using View Base Application. Give the name "AdMobApp".
Step 2: Xcode automatically create the necessary files and directory structure. It also adds necessary frameworks to it.
Step 3: Expands classes and notice "AdMobAppViewController" class. It also has its separate nib file names as AdMobAppViewController.xib.
Step 4: First go to www.admob.com/ We need to register in this site for AdMob.
Step 5: After login go to  Sites & App -> Add Site/App -> Select a Site or App type -> Select iPhone App as Shown in Figure1:


Figure-1
         
Step 6:Now we need to fill full details, see Figure-2 :


Figure-2

Step 7: Now you can download the AbMob SDK, it is required for publishing Ads and drag drop into the Xcode project: (See Figure-3).


 Figure-3




     The AdMob SDK gives 8 files named as GADBannerView.h, GADBannerViewDelegate.h, GADInterstitial.h, GADInterstitialDelegate.h, GADRequest.h, GADRequestError.h, libGoogleAdMobAds.a   and README.txt.

Step 8: Now we need to add new framework in our Xcode project. So select the framework -> add new framework -> Select AudioTollbox.framework, MediaPlayer.framework,MessageUI.framework and SystemConfiguration.framework add in the Framework folder.
Step 9: Now open the AdMobAppViewController.h file. In this file we need to import GADBannerView.h file and create an instance of GADBannerView class as shown below:
     
   #import <UIKit/UIKit.h>
   #import "GADBannerView.h"    
   @interface AdMobAppViewController : UIViewController
    {
         GADBannerView *AbMob;
    }
   @end

 
Step 10: Now open the AdMobAppViewController.m file and make following changes:
         
        #import "AdMobAppViewController.h"
        #define AdMob_ID @"a14f55dfd27dcf7" 
       // You can get this id from www.admob.com. This is Publisher ID
        
       @implementation AdMobAppViewController

          - (void)viewDidLoad
             {
                   [super viewDidLoad];
                  AbMob = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0f,
                                            self.view.frame.size.height -GAD_SIZE_320×70.height,
                                                                            GAD_SIZE_320×70.width,
                                                                           GAD_SIZE_320×70.height)];
   
                    AbMob.adUnitID = AdMob_ID;
                    AbMob.rootViewController = self;
                   [self.view addSubview:AbMob];
 
   
                  GADRequest *r = [[GADRequest alloc] init];
                   r.testing = YES;
                  [AbMob loadRequest:r];
                  [r release];
   
             }

         
          - (void)didReceiveMemoryWarning
            {
                   // Releases the view if it doesn’t have a superview.
                   [super didReceiveMemoryWarning];
   
                   // Release any cached data, images, etc that aren’t in use.
            }

         - (void)viewDidUnload
           {
                [super viewDidUnload];
               // Release any retained subviews of the main view.
               // e.g. self.myOutlet = nil;
           }
           - (BOOL)shouldAutorotateToInterfaceOrientation:
                            (UIInterfaceOrientation)interfaceOrientation
           {
                  // Return YES for supported orientations
                     return (interfaceOrientation == UIInterfaceOrientationPortrait);
           }
       
         - (void)dealloc
          {
              AbMob.delegate = nil;
              [AbMob release];
              [super dealloc];
          }
 
     @end

Step 11: Now Compile and run the project on device. You will see an AdMob Banner on your View




No comments:

Post a Comment