Swiftpack.co - trinhxuanminh/AdMobManager as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by trinhxuanminh.
trinhxuanminh/AdMobManager v3.0.0
AdMobManager - Available for Swift 5.3, Xcode 12.0 (macOS Big Sur). Support from iOS 10.0
⭐️ 7
🕓 Yesterday
.package(url: "https://github.com/trinhxuanminh/AdMobManager.git", from: "v3.0.0")


A package to help support the implementation of ads on your iOS app.

  • For Swift 5.3, Xcode 12.5 (macOS Big Sur) or later.
  • Support for apps from iOS 13.0 or newer.

Ad Type

  • InterstitialAd
  • RewardedAd
  • RewardedInterstitialAd
  • AppOpenAd
  • NativeAd
  • BannerAd


Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. To use AdMobManager with Swift Package Manger, add it to dependencies in your Package.swift.

  dependencies: [
    .package(url: "https://github.com/trinhxuanminh/AdMobManager.git")

Get started

Initial setup as documented by Google AdMob:

Manually add the -ObjC linker flag to Other Linker Flags in your target's build settings:

  • Select target project.
  • Select tab All, find Other Linker Flags.
  • You must set the -ObjC flag for both the Debug and Release configurations.

Integrate Firebase RemoteConfig with any Key name and configure it in this json format. Note: The name of each ad is unique.


Refer to the following Demo project to implement the ad.


Firstly, import AdMobManager.

import AdMobManager

1. Parameter setting

Upgrade premium

This function will block registration, loading, and show ads. Note: Priority to use before registration and use after successful premium purchase.


Register advertising ID

AdMobManager.shared.register(remoteKey: String, defaultData: Data)
  • remoteKey: The Key name you have set on RemoteConfig.
  • defaultData: The data of the default json string in the application, it is used when the remote cannot be loaded.

Complete registration

Add actions after completing registration.

AdMobManager.shared.addActionSuccessRegister(_ handler: @escaping Handler)

2. Control


This function returns the value true/false indicating whether the ad is allowed to show. You can call it to make UI changes, logic in your code.

  • Returns nil when registration is not successful or there is no ad with the corresponding name.
AdMobManager.shared.status(type: AdType, name: String) -> Bool?


This function will start loading ads.

AdMobManager.shared.load(type: Reuse, name: String)


This function will display ads when ready.

  • didShow: The block executes after the ad has disappeared.
  • didFail: The block executes after the ad is not displayed.
AdMobManager.shared.show(name: String,
                         rootViewController: UIViewController,
                         didShow: Handler?,
                         didFail: Handler?)

3. NativeAd

  • Download & add file CustomNativeAdView.xib. Note: Linked outlets to views, update constraints only.
  • Create the corresponding File's owner, inherit NativeAdMobView.
class CustomNativeAdView: NativeAdMobView {
  override func setProperties() {
    binding(nativeAdView: nativeAdView) { [weak self] in
      guard let self = self else {
    load(name: String, rootViewController: nil)
  • Ads will be loaded automatically.
  • Call binding method to display ads when loading successfully.

4. BannerAd

Ads will be loaded automatically. Then, there are two ways you can create BannerAdMobView:

  • By storyboard, changing class of any UIView to BannerAdMobView. Note: Set Module to AdMobManager.
  • By code, using initializer.
bannerAdMobView.load(name: String, rootViewController: nil)


ProX Global

Copyright (c) Trịnh Xuân Minh 2022 @trinhxuanminh


Stars: 7
Last commit: Yesterday
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes


Add Remote Config

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics