Admob is a Google advertising service that includes banners, interstitials, energizes, and (recently added) screens. Admob’s group of agents can be used to bring in ads from other advertisers, including FaceBook, Unity and more than a dozen other platforms. For App integration Admob is a very necessary means of cash.

Go to the official account [iOS Development Stack] to learn more SwiftUI, iOS development related content.

Import the Admob SDK from Cocoapods

The easiest way to import the SDK is through Cocoapods. If you don’t know how to use Cocoapods, check out the official documentation. Add a line of code to your Podfile:

pod 'Google-Mobile-Ads-SDK'
Copy the code

Then execute the command line from the terminal:

pod install --repo-update
Copy the code

Modify the info.plist file of the main project

Add two key-value pairs to the info.plist file of the main project:

  1. GADApplicationIdentifierThis corresponds to the APP ID that your app got from Admob.
  2. SKAdNetworkItemsIt corresponds to a fixedcstr6suwn9.skadnetwork.
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>
<key>SKAdNetworkItems</key>
  <array>
    <dict>
      <key>SKAdNetworkIdentifier</key>
      <string>cstr6suwn9.skadnetwork</string>
    </dict>
  </array>
Copy the code

The info.plist effect after adding:

Information about signing up for an Admob account and obtaining an App ID can be found on the Admob website.

Initialize the Admob SDK

Add the code to initialize the Admob SDK in the AppDelegate

// Objc
@import GoogleMobileAds;

@implementation AppDelegate

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

  [[GADMobileAds sharedInstance] startWithCompletionHandler:nil];
  return YES;
}

@end
Copy the code
// Swift
import GoogleMobileAds

@UIApplicationMain
class AppDelegate: UIResponde.UIApplicationDelegate {
  func application(_ application: UIApplication.didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    GADMobileAds.sharedInstance().start(completionHandler: nil)

    return true}}Copy the code

At this point, we can add the types of ads we want in different parts of the App as needed.

Because there are many types, it would be too long to introduce them separately. So this article will only cover the important points to note, and detailed integration methods can be found on the Admob development website.

Best practices for various Types of Admob ads

Different types of Admob ads are tailored to different scenarios, so not only are they more acceptable to users, but they are also good for AD revenue. On the other hand, failing to display an AD in the recommended way can result in a warning from the advertiser, or even a ban (as we were warned by Facebook).

  1. Banner ads are long banners that are suggested to be placed at the edge of the screen, or at the top or bottom of the screen for mobile phones.
  2. An interstitial AD is a full-screen AD, perhaps a picture or video, that turns off only when the user clicks the close button. This kind of advertisement is very disturbing to users, so it is recommended to display this kind of advertisement when the interface is switched, and not after pushing to a new page, for example, it cannot be displayed in the process of network request server after arriving at a new page.
  3. Native advertising is a special form of advertising. It is loaded with some components of the advertisement (text, picture and video) through SDK. We can customize the display position and size of the components. The AD is suitable for use in the startup diagram or list (UITableView/UICollectionView).
  4. Incentivized video advertising is a form of advertising that allows users to obtain in-app rewards by watching ads, which is very common in game apps. Make sure the user chooses whether or not to see the AD for “more rewards” before the AD pops up.

Use Admob intermediaries to aggregate ads across multiple platforms

Google advertising platform not only has its own Admob Ads but also many other advertising platform resources. On the basis of integrating Google-Mobile-ADS-SDK, we can quickly obtain advertisements from different platforms by adding Mediation from different platforms.

For example, ads integrated with Facebook are pretty much the same on other platforms. If you have any questions during the integration process, you can also ask me at the public account “iOS Development Stack”.

Add the Admob SDK and Facebook mediation group to your Podfile:

pod 'Google-Mobile-Ads-SDK',
pod 'GoogleMobileAdsMediationFacebook'
Copy the code

Then switch to the project directory on the terminal and execute it

CD < current project directory > pod install --repo-updateCopy the code

After installing the Admob SDk and FB AD mediation suite, you can use the corresponding AD form directly. The use of the corresponding form of advertising can be viewed in the previous section, which will not be described here.

One important point to note here is that to initialize the different AD forms you need to call initWithAdUnitID:, where UnitID is the AD wish ID, which can be viewed in Admob’s admin background -> AD Unit page.

Go to the official account [iOS Development Stack] to learn more SwiftUI, iOS development related content. Reply to blog to get free interview questions from major Internet companies.

conclusion

Google’s Admob service is much more well-documented than other advertisers (though it may have errors) and has a vibrant community (I asked a question and got a quick response). This article is a summary of my use process. In addition to the basic integration methods, most of them are matters needing attention in the use process. As for the detailed integration process, please refer to the official documents.

If you have any questions or suggestions, please contact me through the official account.

The article was first posted on my blog