GOOGLE ADMOB INTEGRATION FOR iOS APPS


AdMob is Google’s advertising platform for promoting and monetising mobile applications. AdMob’s platform does majority of the work for you so you can focus on improving your app while making money from it. You also have control over the types of ad formats you allow.

TYPES OF ADMOB ADS:

currently, AdMob has four different types of Ads namely:

  1. Banner Ad   
  2. Interstitial Ad
  3. Native Ad
  4. Rewarded Ad
  1. Banner Ad

Banner ads are rectangular image or text ads that occupy a spot within an app’s layout. They stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time. If you’re new to mobile advertising, they’re a great place to start.

2. Interstitial Ad

Interstitials are full-screen ads that cover the interface of an app until closed by the user. They’re best used at natural pauses in the flow of an app’s execution, such as between levels of a game or just after a task is completed.

   3.  Native Ad

Native is a component-based ad format that gives you the freedom to customize the way assets such as headlines and calls to action are presented in your apps. By choosing fonts, colors, and other details yourself, you can create natural, unobtrusive ad presentations that can add to a rich user experience.

  4.  Rewarded Ad

Rewarded video ads are full-screen video ads that users have the option of watching in their entirety in exchange for in-app rewards.

In this blog we will build a simple Banner Ad that AdMob supports, for this lets  have a look into AdMob account creation.

1 . HOW TO MAKE AN ADMOB ACCOUNT?

  • To create AdMob account search AdMob in google and signup with your Gmail account or you can click here to signup for AdMob account.
  • Read all terms and condition and accept it.
  • Once you follow all the steps your account will be created and you will be landed on the home page of your AdMob account which looks like below screenshot.

admob landing page 

2. HOW TO GENERATE AD UNIT FOR iOS APP?

Generating Ad unit ID for all the Ads i.e Banner Ad, Native Ad, Rewarded Ad and Interstitial Ad is similar. Follow the below steps to generate Ad Unit ID.

  • Click on Apps available on the left side of the dashboard of your AdMob account and select “ADD YOUR FIRST APP” Button.
  • In next screen, you will get a question that Have you published your app on Google Play or the App Store?” and there select “NO”  button.
  • This time you will be redirected to the app information page, there you can enter your App Name and select your Platform (iOS).
  • Congrats! Your app has been added to AdMob. You will be redirected to the page which will give you App ID which looks like “ca-app-pub-45523246750xxxxx~57027xxxxx”. In the same page you have to select “CREATE UNIT ID” button for creating Unit ID for your Banner Ad.
  •  In the next page you will be redirected to the screen, which will be having list of banner types by showing like Banner Ad, Interstitial Ad and Rewarded Ad. As we are building App for Banner, you can select “Banner”.
  • In the Next page you can see the Ad format as Banner and you have to give the name of Ad Unit and click on “CREATE AD UNIT”.
  • Congrats! Now your Ad unit successfully created. In that page you can able to see both of your App ID and  ad unit ID, which looks like as below.

        App ID: “ca-app-pub-45523246750xxxxx~57027xxxxx”

  Ad Unit ID: “ca-app-pub-45523246750xxxxx/47689xxxxx

  • Click Done if you have finished or hit on Create Another AD Unit to create another app ID and Unit ID.
  • For all above process of creating App ID and Unit ID, here I am attaching some screenshots for your reference. Please have a look.

 

 

 

add your first app

 

select option for admob publishing

 

selecting ios app

 

Unit Id

 

Banners

 

Ad Unit name filling

Ad unit creted

Now App ID and Unit ID created. So we will jump on coding part !!! Now Lets see how to Integrate Admob into our iOS Applications, with our all above credentials.

3. INTEGRATING ADMOB INTO IOS APPS

  • Open Xcode , Create new file by clicking FILE => New => FILE. Now you can choose a template for your new file as “Cocoa Touch Class” , click on Next and Give a class name what ever you want and click on “Next”. (In my project I have given class name as ViewController).
  • Now Open AppDelegate.m file and importGoogleMobileAds” SDK and place your App ID in application didFinishLaunchingWithOptions Method as shown below screen shot.

4. CREATING BANNER VIEW

  • Now It’s time to create a view for Banner Ad and set width, height positions for that in viewDidLoad. So for creating banner view lets first declare a property for that in ViewController’s Interface area,  and in that declare one method for banner request. (A banner request is Specifies optional parameters for ad requests,  and the method which was created by us is returns a default request by implementing banner delegates.). Implement delegate for banner ad implementation. The code for banner creation is shown below.

#import "ViewController.h"
@import GoogleMobileAds;

@interface ViewController ()<GADBannerViewDelegate>
//@property(nonatomic, strong) GADBannerView *bannerView;
-(GADRequest *)Createrequest;
@property (weak, nonatomic) IBOutlet GADBannerView *bannerView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Creating Banner Ads !
  
   _bannerView.delegate = self;
    self.bannerView.adUnitID=@"ca-app-pub-9429798427460185/9675986153";
//    [self.bannerView setRootViewController:self];
    [self.bannerView loadRequest:[self Createrequest]];
    
}

 

 5.  IMPLEMENTING BANNER DELEGATE

  • To handling AdMob,  Apple has provided some Delegate methods, Which are

      1) bannerView didFailToReceiveAdWithError

      2)adViewDidReceiveAd

  1) bannerView didFailToReceiveAdWithError:

As the name suggests that when ever is there any error occurs while we are working with AdMob’s this method will be handles those events.

  2)adViewDidReceiveAd:

So if everything goes smoothly, and our code executes fine, and our App ID, Unit ID..etc will be works fine, the banner request will be executed by this method and you can able to see our Banner Ad.

  • So the implementation process of GADBannerViewDelegate is shown below code.
#pragma Mark--- GADBannerView Delegate Methods
-(GADRequest *)Createrequest

{
    GADRequest *request=[GADRequest request];
    return request;
}

-(void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(GADRequestError *)error

{
    NSLog(@"Failed With Error %@",[error localizedFailureReason]);
}

-(void)adViewDidReceiveAd:(GADBannerView *)adView

{

    NSLog(@"The received add is %@",adView);
 
    [self.bannerView setHidden:NO];
}
@end

 

Now Everything was done. You can Run your application.. Now you can able to see your First banner Ad developed by you Cheers ..!!!

You can see Our Banner Ad in below screenshot.

iphone x