Hi friends , As we all know that apple officially shutdown iAds in June 2016.  So I was going through many blogs and finally came up with this google ADMobs. Today we will learn how to integrate ADMobs in iOS applications.

Steps:

  1. Create a new Xcode Project Lets say AdMobObjectiveC.
  2. First go to this firebase link and create a firebase account.
  3. Click on Create New Project button on the page.screen-shot-2017-01-29-at-1-40-22-am
  4. Give the Project Name and select the country and click Create Project.screen-shot-2017-01-29-at-1-40-47-am
  5.  Now click on Add Firebase to your iOS app.screen-shot-2017-01-29-at-1-41-00-am
  6.  Fill the iOS Bundle id and optional Name and click on ADD APP buttonscreen-shot-2017-01-29-at-1-41-09-am
  7.  After that a GooglePlist will be downloaded which will contain AdId of your Project. Just Add this Plist in Your project.screen-shot-2017-01-29-at-1-42-27-am
  8.  Now Press CONTINUE Button.screen-shot-2017-01-29-at-1-42-44-am
  9.  And Finally Press Finish and Your firebase account with the project is configured.
  10.  Now Next step is downloading the SDK. Go to this link and click on framework SDK zip.screen-shot-2017-01-29-at-1-06-12-am
  11. Once it is downloaded . Unzip it . Copy and paste GoogleADMob Framework into your project.screen-shot-2017-01-29-at-1-27-56-am
  12. Now its time for Small Coding. Go to your AppDelegate.m and import the framework and the below line of code. You will get the ADId from your Google Plist.
  13. #import “AppDelegate.h”

    #import <GoogleMobileAds/GoogleMobileAds.h>

    @interface AppDelegate ()

    @end

    @implementation AppDelegate

    – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        // Override point for customization after application launch.

        [GADMobileAds configureWithApplicationID:@”Your-ADMob-UNITP-ID”];

        return YES;

    }

    14 Now go to storyBoard and take a view in below with size 320 * 50. Replace the class name with GADBannerView and then make IBOutLetConnection for this View.

    screen-shot-2017-01-29-at-2-42-34-am15. Your ViewController.h will look something like this after the connection.

#import <UIKit/UIKit.h>

#import <GoogleMobileAds/GoogleMobileAds.h>

@interface ViewController : UIViewController

@property(nonatomic, weak) IBOutlet GADBannerView *bannerView;

@end

16. Now go to ViewController.m and  modify the code with below code

#import “ViewController.h”

#import <GoogleMobileAds/GoogleMobileAds.h>

@interface ViewController ()<GADBannerViewDelegate>

@end

@implementation ViewController

– (void)viewDidLoad {

    [super viewDidLoad];

    self.bannerView.adUnitID = @”**your ADMobo Device ID *****”;

    self.bannerView.rootViewController = self;

// Comment the below line if You are not implementing delegate method.

    self.bannerView.delegate = self;

    

    GADRequest *request = [GADRequest request];

    // Requests test ads on devices you specify. Your test device ID is printed to the console when

    // an ad request is made. GADBannerView automatically returns test ads when running on a

    // simulator.

// If you are using Simulator for testing then no need of adding test devices.

    request.testDevices = @[

                            @”-***Device UDID**_”

                            ];

    [self.bannerView loadRequest:request];

    // Do any additional setup after loading the view, typically from a nib.

}

17. Run the code .. You will see the output like this.

screen-shot-2017-01-29-at-2-47-54-am

18 You can also implement the delegate method to  find whether the ads have been loaded or not.

– (void)adViewDidReceiveAd:(GADBannerView *)bannerView {

    NSLog(@”Ad Loaded”);

}

– (void)adView:(GADBannerView *)adView didFailToReceiveAdWithError:(GADRequestError *)error {

    NSLog(@”adView:didFailToReceiveAdWithError: %@”, error.localizedDescription);

}

Please share your reviews.

Enjoy Coding 🙂

Advertisements