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 v1.5.6
AdMobManager - Available for Swift 5.3, Xcode 12.0 (macOS Big Sur). Support from iOS 10.0
⭐️ 6
🕓 2 weeks ago
.package(url: "https://github.com/trinhxuanminh/AdMobManager.git", from: "v1.5.6")


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 10.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:

Set the -ObjC linker flag at Info.plist:


Note: If you have Firebase, install it using Swift Package Manager to avoid conflicts.


Firstly, import AdMobManager.

import AdMobManager

1. Parameter setting

Advertising ID

This function helps to register ads by unique key.

AdMobManager.shared.register(key: String, type: AdType, id: String)

Deployment Time (Optional)

This function helps to set the date to start showing ads.

  • Default is nil, the ad will be displayed as soon as it is ready.
  • Changes only for InterstitialAd, RewardedAd, RewardedInterstitialAd, AppOpenAd.
AdMobManager.shared.showFullFeature(from: Date)

Time between (Optional)

This function helps to change the minimum display time between ads of the same type.

  • Default is 0 seconds.
AdMobManager.shared.setTimeBetween(key: String, time: Double)

2. Control


This function returns a value true/false indicating if the ad is ready to be displayed.

  • Returns nil when there is no advertisement with the corresponding key.
AdMobManager.shared.isReady(key: String) -> Bool?


This function will display ads when ready.

  • willPresent: The block executes after the ad is about to show.
  • willDismiss: The block executes after the ad is about to disappear.
  • didDismiss: The block executes after the ad has disappeared.
  • didFail: The block executes after the ad failed to display the content.
AdMobManager.shared.show(key: String)

3. NativeAd

Ads are displayed automatically. Includes types: FullScreen Bonus Medium Size1...Size9

a) CollectionViewCell

This class returns a UICollectionViewCell displaying NativeAd.

collectionView.register(ofType: Size1NativeAdCollectionViewCell.self)
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  let cell = collectionView.dequeue(ofType: Size1NativeAdCollectionViewCell.self, indexPath: indexPath)
  cell.adView.register(id: String)
//            Optional
  return cell

b) TableViewCell

This class returns a UITableViewCell displaying NativeAd.

tableView.register(ofType: Size1NativeAdTableViewCell.self)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  let cell = tableView.dequeue(ofType: Size1NativeAdTableViewCell.self, indexPath: indexPath)
//            Optional
  return cell

c) View

There are two ways you can create a UIView displaying NativeAd:

  • By storyboard, changing class of any UIView to Size1NativeAdView. Note: Set Module to AdMobManager.
  • By code, using initializer.

d) Determine the height

Size5NativeAdCollectionViewCell.adHeightMinimum(width: collectionView.frame.width)

e) Optional


4. BannerAd

Ads are displayed automatically. Then, there are two ways you can create BannerAdView:

  • By storyboard, changing class of any UIView to BannerAdView. Note: Set Module to AdMobManager.
  • By code, using initializer.


ProX Global

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


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

Release Notes

2 weeks ago

Add size10, 11 NativeAds

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