Ideally, we want to have our code completely dependency-free and preserve control over its entire functioning. In the real world, we know this is unrealistic since it would imply reinventing the wheel over and over.
AdsEngine centralizes the ad's SDKs and exposes them via facades.
Contracts expire, SDKs get deprecated and fees rises. These, just to mention a few, are valid reasons to change ad's vendors.
This is rather hard when our codebases are littered with direct SDKs implementations. AdsEngine makes such processes painless by making their consumption behind a facade. This is why, whatever happens under the hood shall not concern our clients apps.
- From the File menu, Add Packages….
- Enter package repository URL:
https://github.com/GeekingwithMauri/AdsEngine - Confirm the version and let Xcode resolve the package
If you want to use AdsEngine in any other project that uses SwiftPM, add the package as a dependency in Package.swift:
dependencies: [
.package(
url: "https://github.com/GeekingwithMauri/AdsEngine",
from: "0.1.0"
),
]Within the desired place (usually a ViewController) where an ad is going to be shown, add the following:
import AdsEngine
class SomeViewController {
private lazy var bannerContainer: UIView = {
let container = UIView(frame: .zero)
container.translatesAutoresizingMaskIntoConstraints = false
return container
}()
private lazy var bannerAd: BannerProvider = {
let banner = BannerProvider(identifier: "ad identifier")
banner.initBannerToBeIncluded(in: bannerContainer)
banner.adDelegate = self
return banner
}()
override func viewDidLoad() {
super.viewDidLoad()
...
bannerAd.loadAd(for: self)
}
}
extension SomeViewController: AdInteractable {
func adLoaded() {
print("Banner loaded!")
}
func failedToPresent(dueTo error: Error) {
print("Banner failed to init due to \(error.localizedDescription)")
}
}AdInteractable also offers adDidRecordImpression(), the vendor's own "this ad
was seen" signal. It defaults to a no-op — the conformer above is complete
without it — so implement it only if you count ad exposure. Prefer it over
adLoaded() for that: an ad can load and never be rendered.
pending doc
AdMob ships configured to drive the host app's AVAudioSession around its video
creatives — it sets the category to .ambient while they're muted and
.soloAmbient when one unmutes, both of which the Ring/Silent switch silences.
An app that plays its own sound through a silenced phone therefore goes quiet the
moment an ad is requested, and stays quiet, since nothing restores the category.
AdsEngine turns that off for you on the first ad request: the vendor still
handles audio inside its own creatives, it just stops rewriting your category.
Nothing to call. If you actually want the SDK holding the session, set
MobileAds.shared.audioVideoManager.isAudioSessionApplicationManaged = false
after your first loadAd.
pending doc
- For the time being, this only supports Google's AdsMob.
GoogleService-Infomust be included in the main project