Skip to content

GAdsManager is a Google Mobile Ads Sdk based library to use all my iOS apps to show and manage ads.

License

Notifications You must be signed in to change notification settings

mahmudahsan/GAdsManager

Repository files navigation

GAdsManager

thinkdiff.net Youtube ithinkdiff.net Twitter: @mahmudahsan

GAdsManager is a in app advertise management library which I am using in all my iOS apps and games. This library is developed based on Google Mobile Ads SDK. Currently I am refactoring my old codebase and improving it to make a reusable library. In This library, I am combining all of the features over time including banner ads, interestial, reward video etc. so that one library can handle many different ads situation.

This GAdsManager is a loosely coupled component. So its easy to use in any iOS project. It is also possible to replace Google AdMob by other 3rd party ad network library. As it's a loosely coupled, it doesn't need to update the ads integration code in the app just need to update GAdsManager layer which saves time and complexity.

How GAdsManage Works

Features

  • Loosely coupled component
  • Banner ads following Google AdMob Guideline
  • Banner ads with 5 pixel black border above
  • Banner ads automatically adjust for portrait and landscape
  • Banner ads works on both iPhone and iPad
  • Interestial ads
  • Rewarded Video ads

Demo Banner Bottom Banner Bottom Landscape Banner Bottom iPad Landscape Banner Bottom iPad Portrait

Examples Banner

Integrate bottom banner ads within a UIViewController via code:

import UIKit

enum AdIds : String {
    // FIXME:- Follow the link to know how to add AppId in Info.plist
    // https://developers.google.com/admob/ios/quick-start#update_your_infoplist
    
    // FIXME:-  REPLACE THE VALUES BY YOUR APP AND AD IDS
    case banner      = "ca-app-pub-3940256099942544/2934735716" // test id
    case interestial = "ca-app-pub-3940256099942544/4411468910" // test id
    case rewarded    = "ca-app-pub-3940256099942544/1712485313" // test id
}

let testDevices = [
    "XX",   //iPhone 5s
    "YY", // iPhone 6
]

//Call admanager with a delay so that safeAreaGuide value calculated correctly
AdManager.shared.configureWithApp()
AdManager.shared.setTestDevics(testDevices: testDevices)
AdManager.shared.delegateBanner = self
dManager.shared.createBannerAdInContainerView(viewController: self, unitId: AdIds.banner.rawValue)

Get notification when banner ad received or failed by implementing the protocol and by setting the delegate:

public protocol AdManagerBannerDelegate{
    func adViewDidReceiveAd()
    func adViewDidFailToReceiveAd()
    func adViewWillPresentScreen()
    func adViewWillDismissScreen()
    func adViewDidDismissScreen()
    func adViewWillLeaveApplication()
}

Examples Interestial

Request a new Interestial ad which will loaded in memory

AdManager.shared.createAndLoadInterstitial(AdIds.interestial.rawValue)
AdManager.shared.delegateInterestial = self

Show interestial ads. self refers to the UIViewController

let isReady = AdManager.shared.showInterestial(self)

Get notification about interestial ads

public protocol AdManagerBannerDelegate{
    func interestialDidReceiveAd()
    func interestialDidFailToReceiveAd()
    func interestialWillPresentScreen()
    func interestialWillDismissScreen()
    func interestialDidDismissScreen()
    func interestialWillLeaveApplication()
}

Interestial Portrait

Examples Rewarded Video Ads

Request a new Rewarded Video ads and show immediately after loading.

AdManager.shared.loadAndShowRewardAd(AdIds.rewarded.rawValue, viewController: self)
AdManager.shared.delegateReward = self

Get notification about Rewarded Video ads

public protocol AdManagerRewardDelegate{
    func rewardAdGiveRewardToUser(type:String, amount: NSDecimalNumber)
    func rewardAdFailedToLoad()
    func rewardAdDidReceive(
        rewardViewController: UIViewController?,
        rewardedAd: GADRewardedAd?,
        delegate: AdManager
    )
    func rewardAdDidOpen()
    func rewardAdDidClose()
    func rewardAdFailedToPresent()
}

Give reward to user when user completes viewing a video ad

extension ViewController : AdManagerRewardDelegate {
    func rewardAdGiveRewardToUser(type: String, amount: NSDecimalNumber) {
        print("User Seen the Ads. Now give reward to him")
    }
}

Rewarded Video Ads

Dependency

  • Add pod 'Google-Mobile-Ads-SDK' in your podfile and install Google-Mobile-Ads-Sdk Framework in your project via CocoaPods.

Usage in an iOS application

  • Drag the folders GAdsManager/Source folder into your application's Xcode project.

Questions or feedback?

Feel free to open an issue, or find me @mahmudahsan on Twitter.