How To Integrate Admob Rewarded Ad Swift

How To Integrate Admob Rewarded Ad Swift

Before integrating Admob rewarded ads into your app, create an Admob account and download the SDK using Cocoapods.

pod 'Google-Mobile-Ads-SDK' # Mobile ads google

Testing Ads

It’s always advised you use a test Ad unit when testing your apps. Testing your app using live ads could lead to your account being terminated or suspended. Admob’s available to test ads:

FormatSizeAd unit ID
Banner (MRect)300×2502aae44d2ab91424d9850870af33e5af7
Rewarded Ad320×4808f000bd5e00246de9c789eed39ff6096
Rewarded Playable (MRAID)320×48098c29e015e7346bd9c380b1467b33850

Load Ads

The first step in integrating your Ad is by initialising it in your App Delegate. To initialise your Ads, import Admob and configure your ads.

import GoogleMobileAds // Mobile advertising

class AppDelegate: UIResponder, UIApplicationDelegate {

     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:    [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Google services
        Messaging.messaging().delegate = self
        GADMobileAds.sharedInstance().start(completionHandler: nil)

In your UIViewController, import the GoogleMobileAds and set your variables such as your google ad unit and your GADRewardAd.

import UIKit
import GoogleMobileAds // Google Ads

class SettingsViewController: UIViewController {

// Your ad unit
let rewardAdUnit = "YOUR_AD_UNIT"
// Ad unit
var rewardedAd: GADRewardedAd?

override func viewDidLoad() {

Create a function to be called when users perform certain actions such as when a user clicks a button, closes a view or something similar. The function can be seen below.

@objc func loadRewardedAd(){
            withAdUnitID: self.rewardAdUnit, request: GADRequest()
            ) { (ad, error) in
              if let error = error {
                print("Rewarded ad failed to load with error: \(error.localizedDescription)")
              print("Loading Succeeded")
                self.rewardedAd = ad
                self.rewardedAd?.fullScreenContentDelegate = self
                if self.rewardedAd != nil {
                         self.rewardedAd?.present(fromRootViewController: self, userDidEarnRewardHandler: {
                 } else {
                           // Some other error encountered

Reward User

Place your function or script to reward users in the last function.

extension ViewController: GADFullScreenContentDelegate {
    func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
       print("Rewarded ad presented.")

     func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
       print("Rewarded ad dismissed.")
         // Reward user here

Going Live

That’s it, you’ve added Admob rewarded ads to your app. Once you are ready to go live, change your app unit to the one you’ve created on Admob.

Monitor Revenue

To monitor your app’s monetisation, set targets and much more download our Motics app. Learn more about it here.

Leave a Reply