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

AdMobManager

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

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

Ad Type

  • SplashAd
  • InterstitialAd
  • AppOpenAd
  • NativeAd
  • BannerAd

Installation

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:

<key>GADIsAdManagerApp</key>
  <true/>

Usage

Firstly, import AdMobManager.

import AdMobManager

1. Parameter setting

Advertising ID

This function helps to change the ad ID, available for the next load.

  • Ad parameters is nil will not load the corresponding ad type.
AdMobManager.shared.set_AdUnit(splashAd_ID: String?, interstitialAd_ID: String?, appOpenAd_ID: String?, nativeAd_ID: String?, bannerAd_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 SplashAd, InterstitialAd, AppOpenAd.
AdMobManager.shared.set_Time_Show_Full_Feature(start: Date)

Time between (Optional)

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

  • Default is 5 seconds.
  • Changes only for InterstitialAd, AppOpenAd.
e.g.
AdMobManager.shared.set_Time_Between(adType: AdMobManager.AdType, time: Double)

2. Control

is_Ready()

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

e.g.
AdMobManager.shared.is_Ready(adType: AdMobManager.AdType)

show()

This function will display ads when ready.

Parameters:
  • 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.
e.g.
AdMobManager.shared.show(adType: AdMobManager.AdType)

3. NativeAd

Ads are displayed automatically.

a) NativeAdCollectionViewCell / NativeAdvancedAdCollectionViewCell

This class returns a UICollectionViewCell displaying NativeAd.

Register
collectionView.register(UINib(nibName: NativeAdCollectionViewCell.className, bundle: AdMobManager.bundle), forCellWithReuseIdentifier: NativeAdCollectionViewCell.className)
collectionView.register(UINib(nibName: NativeAdvancedAdCollectionViewCell.className, bundle: AdMobManager.bundle), forCellWithReuseIdentifier: NativeAdvancedAdCollectionViewCell.className)
Datasource
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let collectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: NativeAdCollectionViewCell.className, for: indexPath) as! NativeAdCollectionViewCell
//            Optional
    return collectionViewCell
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let collectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: NativeAdvancedAdCollectionViewCell.className, for: indexPath) as! NativeAdvancedAdCollectionViewCell
//            Optional
    return collectionViewCell
}

b) NativeAdTableViewCell / NativeAdvancedAdTableViewCell

This class returns a UITableViewCell displaying NativeAd.

Register
tableView.register(UINib(nibName: NativeAdTableViewCell.className, bundle: AdMobManager.bundle), forCellReuseIdentifier: NativeAdTableViewCell.className)
tableView.register(UINib(nibName: NativeAdvancedAdTableViewCell.className, bundle: AdMobManager.bundle), forCellReuseIdentifier: NativeAdvancedAdTableViewCell.className)
Datasource
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let tableViewCell = tableView.dequeueReusableCell(withIdentifier: NativeAdTableViewCell.className, for: indexPath) as! NativeAdTableViewCell
//            Optional
    return tableViewCell
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let tableViewCell = tableView.dequeueReusableCell(withIdentifier: NativeAdvancedAdTableViewCell.className, for: indexPath) as! NativeAdvancedAdTableViewCell
//            Optional
    return tableViewCell
}

c) NativeAdView / NativeAdvancedAdView

Then, there are two ways you can create NativeAdView / NativeAdvancedAdView:

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

d) Optional

.set_Color(style: AdMobManager.Style?, backgroundColor: UIColor?, themeColor: UIColor?)
.set_Loading_Type(type: NVActivityIndicatorType)
.setAd(index: Int)

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.

5. Error handling options

Limit reloading

This function helps to limit the reload of the ad when an error occurs.

  • Time reload ads after failed load.
  • Unit is milliseconds.
  • Default is 1000 milliseconds, ad will be reloaded immediately.
AdMobManager.shared.limit_Reloading_Of_Ads_When_There_Is_An_Error(adReloadTime: Int)

Note: For iOS 11.4 and below, InterstitialAd and AppOpenAd will reload immediately after the failed impression.

Stop loading SplashAd

This function helps to block reloading of SplashAd.

  • Recommended when splash ads don’t need to appear anymore.
AdMobManager.shared.stop_Loading_SplashAd()

isConnected()

This function return about an value for know the path is available to establish connections and send data.

  • Available for iOS 12.0 or newer.
AdMobManager.shared.isConnected()

License

ProX Global

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

GitHub

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

Release Notes

1.1.0
2 weeks ago

Fix not show star image

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