Skip to content
GeekingwithMauriPublic

About

Ad's wrapper to preserve your codebase dependency free from 3rd-party vendors.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

AdsEngine

Rationale

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.

What's the point?

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.

Installation

Xcode 13

  1. From the File menu, Add Packages….
  2. Enter package repository URL: https://github.com/GeekingwithMauri/AdsEngine
  3. Confirm the version and let Xcode resolve the package

Swift Package Manager

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"
  ),
]

Example of usage

Banner usage

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.

Interstitial usage

pending doc

Your audio session stays yours

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.

Testing

pending doc

Current limitations

  • For the time being, this only supports Google's AdsMob.
  • GoogleService-Info must be included in the main project

About

Ad's wrapper to preserve your codebase dependency free from 3rd-party vendors.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages