A package to help support the implementation of ads on your iOS app.
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")
]
Initial setup as documented by Google AdMob:
Set the -ObjC linker flag at Info.plist
:
<key>GADIsAdManagerApp</key>
<true/>
Note: If you have Firebase, install it using Swift Package Manager to avoid conflicts.
Firstly, import AdMobManager
.
import AdMobManager
This function helps to register ads by unique key.
AdMobManager.shared.register(key: String, type: AdType, id: String)
This function helps to set the date to start showing ads.
InterstitialAd
, RewardedAd
, RewardedInterstitialAd
, AppOpenAd
.AdMobManager.shared.showFullFeature(from: Date)
This function helps to change the minimum display time between ads of the same type.
AdMobManager.shared.setTimeBetween(key: String, time: Double)
This function returns a value true/false indicating if the ad is ready to be displayed.
AdMobManager.shared.isReady(key: String) -> Bool?
This function will display ads when ready.
AdMobManager.shared.show(key: String)
Ads are displayed automatically.
Includes types:
FullScreen
Bonus
Medium
Size1
...Size9
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
}
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
}
There are two ways you can create a UIView displaying NativeAd:
UIView
to Size1NativeAdView
. Note: Set Module
to AdMobManager
.Size1NativeAdView.adHeight()
Size5NativeAdCollectionViewCell.adHeightMinimum(width: collectionView.frame.width)
.changeColor()
.changeFont()
.changeLoading()
Ads are displayed automatically.
Then, there are two ways you can create BannerAdView
:
UIView
to BannerAdView
. Note: Set Module
to AdMobManager
.link |
Stars: 6 |
Last commit: 2 weeks ago |
Add size10, 11 NativeAds
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics