Integrate with AdMob

If you already have AdMob ads serving in your app, you can integrate AwesomeAds without having to use the AwesomeAds Publisher SDK directly.

Add the AdMob plugin

  1. Add the following to your Podfile. This is usually in the root directory of your app’s project:
    target 'MyProject' do
     # add the SuperAwesome SDK
     pod 'SuperAwesome', '~> 9.4.0'
    
     # add the AdMob plugin
     pod 'SuperAwesomeAdMob', '~> 9.4.0'
    end
    
  2. Execute this command:
    pod update
    

Set up iOS AdMob Mediation Groups

Next, you need to set up a Mediation Group for each type of AdMob ad that you wish to display: banner, interstitial, and video.

  1. Log in to the AdMob dashboard.
  2. For this tutorial, assume you have set up an iOS app with three ad units in AdMob: one banner ad, one interstitial ad, and one rewarded video ad:
    image-title-here

  3. In the Mediation menu, create a new iOS Mediation Group:
    image-title-here

  4. Enter the Mediation Group details:
    image-title-here

  5. Add your app’s banner Ad Unit as target:
    image-title-here

  6. In the Ad Sources panel, add a new Custom Event:
    image-title-here
    image-title-here

  7. Customize the Custom Event:
    image-title-here
  • Class Name: SAAdMobAdapter
  • Parameter: This is your placementId

You should now have at least two different ad sources. Save your changes.

Finally, save your changes. This will register a custom banner event. You’ll have to repeat the same process for interstitial and rewarded video ads.

Implement AdMob ads

After you set up the AdMob Mediation Groups, you can add AdMob banners, interstitials, and rewarded video ads as normal:

Add an AdMod banner

  1. Create the banner request:
let bannerReq = GADRequest()
GADRequest *bannerReq = [GADRequest request];
  1. Add the banner view:
let banner = GADBannerView(adSize: GADAdSizeBanner)
banner.adUnitID = "__YOUR_ADMOB_UNIT_ID__"
banner.rootViewController = self
view.addSubview(banner)
banner.load(bannerReq)
GADBannerView *banner = [[GADBannerView alloc] initWithAdSize: GADAdSizeBanner];
banner.adUnitID = @"__YOUR_ADMOB_UNIT_ID__";
banner.rootViewController = self;
[self.view addSubview: banner];
[banner loadRequest: bannerReq];

Add an AdMob interstitial ad

  1. Create the interstitial request:
let interstitialReq = GADRequest()
GADRequest *interstitialReq = [GADRequest request];
  1. Add the interstitial ad:
var ad: GADInterstitialAd?
GADInterstitialAd.load(withAdUnitID: "__YOUR_ADMOB_UNIT_ID__",
                       request: interstitialReq,
                       completionHandler: { interstitialAd, error in
    if let error = error {
        print("Failed to load intersitial ad with error: \(error.localizedDescription)")
        return
    }
    ad = interstitialAd
    print("Intersitial ad loaded.")
})
__block GADInterstitialAd *ad;
[GADInterstitialAd loadWithAdUnitID:@"__YOUR_ADMOB_UNIT_ID__"
                            request:interstitialReq
                  completionHandler:^(GADInterstitialAd * _Nullable interstitialAd, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Failed to load interstitial ad with error: \(error.localizedDescription)");
        return;
    }
    ad = interstitialAd;
    NSLog(@"Interstitial ad loaded.");
}];

Add an AdMob rewarded video ad

  1. Create the rewarded video request:
let videoReq = GADRequest()
GADRequest *videoReq = [GADRequest request];
  1. Add the rewarded video ad:
var ad: GADRewardedAd?
GADRewardedAd.load(withAdUnitID:"__YOUR_ADMOB_UNIT_ID__",
                           request: videoReq,
                           completionHandler: { rewardedAd, error in
    if let error = error {
        print("Failed to load rewarded ad with error: \(error.localizedDescription)")
        return
    }
    ad = rewardedAd
    print("Rewarded ad loaded.")
})
__block GADRewardedAd *ad;
[GADRewardedAd loadWithAdUnitID:@"__YOUR_ADMOB_UNIT_ID__"
                        request:videoReq
              completionHandler:^(GADRewardedAd * _Nullable rewardedAd, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Failed to load rewarded ad with error: \(error.localizedDescription)");
        return;
    }
    ad = rewardedAd;
    NSLog(@"Rewarded ad loaded.");
}];

Since the previously created custom events will run on these ads, and AwesomeAds is integrated alongside the AdMob plugin, you should start seeing ads playing.

Customize the experience

You can customize the experience of each ad unit by creating an options object that sets the ad parameters. The AdMob Plugin passes these parameters to the AwesomeAds SDK so that the ads display the way you want them to.

Customize a banner ad

  1. Create an options object where you set the parameters for an AwesomeAds banner ad:
let options = SAAdMobCustomEventExtra()
options.testEnabled = false
options.parentalGateEnabled = true
options.trasparentEnabled = true
SAAdMobCustomEventExtra *options = [[SAAdMobCustomEventExtra alloc] init];
options.testEnabled = false;
options.parentalGateEnabled = true;
options.trasparentEnabled = true;
  1. Create a standard GADCustomEventExtras object:
let extra = GADCustomEventExtras()
GADCustomEventExtras *extra = [GADCustomEventExtras new];
  1. Assign to it the options object you created above. The label for which you add the options object must be
    the same as the name of the custom mediation event you created:
extra.setExtras(options as! [AnyHashable : Any], forLabel: "BannerCustomEvent")
[extra setExtras: options forLabel: @"BannerCustomEvent"];
  1. Register the GADCustomEventExtras object with this request:
bannerReq.register(extra)
[bannerReq registerAdNetworkExtras: extra];

Customize an interstitial ad

  1. Create an options object where you set the parameters for an AwesomeAds interstitial ad:
let options = SAAdMobCustomEventExtra()
options.testEnabled = false
options.parentalGateEnabled = true
options.orientation = .portrait
SAAdMobCustomEventExtra *options = [[SAAdMobCustomEventExtra alloc] init];
options.testEnabled = false;
options.parentalGateEnabled = true;
options.orientation = OrientationPortrait;
  1. Create a standard GADCustomEventExtras object:
let extra = GADCustomEventExtras()
GADCustomEventExtras *extra = [GADCustomEventExtras new];
  1. Assign to it the options object created above. The label for which you add the options object must be the same as the name of the custom mediation event you created:
extra.setExtras(options as! [AnyHashable : Any], forLabel: "InterstitialCustomEvent")
[extra setExtras: options forLabel:@"InterstitialCustomEvent"];
  1. Register the GADCustomEventExtras object with this request:
interstitialReq.register(extra)
[interstitialReq registerAdNetworkExtras: extra];

Customize a rewarded video ad

  1. Create an options object where you set the parameters for an AwesomeAds video ad:
let options = SAAdMobVideoExtra()
options.testEnabled = false
options.closeAtEndEnabled = true
options.closeButtonEnabled = false
options.parentalGateEnabled = false
options.smallCLickEnabled = true
options.orientation = .landscape
SAAdMobVideoExtra *options = [[SAAdMobVideoExtra alloc] init];
options.testEnabled = false;
options.closeAtEndEnabled = true;
options.closeButtonEnabled = false;
options.parentalGateEnabled = false;
options.smallCLickEnabled = true;
options.orientation = OrientationLandscape;
  1. Register the options object with this request:
videoReq.register(options)
[videoReq registerAdNetworkExtras: options];