Swiftpack.co - GeekingwithMauri/AdsEngine as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by GeekingwithMauri.
GeekingwithMauri/AdsEngine 0.1.0
Ad's wrapper to preserve your codebase dependency free from 3rd-party vendors.
⭐️ 1
🕓 3 weeks ago
iOS
.package(url: "https://github.com/GeekingwithMauri/AdsEngine.git", from: "0.1.0")

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 Tracking 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)")
    }
}

Interstitial usage

pending doc

Testing

pending doc

Current limitations

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

GitHub

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

Release Notes

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