Overview
The Google AdMob Ads SDK lets app developers display ads from the Google AdMob network within their iOS apps. This document provides detailed information on how to integrate the SDK into your project and start monetizing your app effectively with ads.
Requirements
- iOS 8.0 or later
- Xcode 10 or later
- Swift 4.2 or Objective-C
Getting Started
To get started with the Google AdMob Ads SDK, follow the steps below:
- Create a new iOS project or open an existing one in Xcode.
- Download the latest version of the Google AdMob Ads SDK from the official website.
- Extract the downloaded SDK package.
- In Xcode, open your project and locate the project navigator panel.
- Right-click on the “Frameworks” folder and select “Add Files to [Your Project Name]”.
- Navigate to the extracted SDK folder and select the appropriate framework (.framework) file.
- Click “Add” to add the SDK framework to your project.
- In Xcode, locate your app’s Info.plist file.
- Add the following entry:
<key>GADApplicationIdentifier</key>
<string>YOUR_ADMOB_APP_ID</string>
Note: Replace “YOUR_ADMOB_APP_ID” with your actual AdMob app ID.
With the SDK successfully integrated into your project, you can now proceed to implement ad units and display ads in your app.
Implementing Ad Units
Ad units are the building blocks of the AdMob Ads SDK. They determine the types of ads that can be displayed in your app.
Banner Ads
To implement a banner ad unit:
- Create a new banner view instance.
- Set the ad unit ID of the banner view.
- Configure the banner view optional properties.
- Load and display the banner ad.
let bannerView = GADBannerView(adSize: kGADAdSizeBanner)
bannerView.adUnitID = "YOUR_BANNER_AD_UNIT_ID"
Note: Replace “YOUR_BANNER_AD_UNIT_ID” with your actual banner ad unit ID.
bannerView.rootViewController = self
bannerView.delegate = self
bannerView.load(GADRequest())
Interstitial Ads
To implement an interstitial ad unit:
- Create a new interstitial ad instance.
- Set the delegate for the interstitial ad.
- Load the interstitial ad.
- Display the interstitial ad at an appropriate moment.
let interstitial = GADInterstitial(adUnitID: "YOUR_INTERSTITIAL_AD_UNIT_ID")
Note: Replace “YOUR_INTERSTITIAL_AD_UNIT_ID” with your actual interstitial ad unit ID.
interstitial.delegate = self
interstitial.load(GADRequest())
if interstitial.isReady {
interstitial.present(fromRootViewController: self)
} else {
print("Interstitial ad is not ready.")
}
Customizing Ads
The AdMob Ads SDK provides various options to customize the appearance and behavior of ads within your app. These options include:
- Changing the ad size
- Configuring ad targeting
- Setting up ad refresh intervals
- Implementing interstitial ad callbacks
- Customizing banner ad appearance
To learn more about advanced customization options, refer to the official AdMob documentation.
Additional Resources
For additional information and resources on integrating and utilizing the Google AdMob Ads SDK, see the following: