Skip to content

Instantly share code, notes, and snippets.

@Ilesh
Created August 8, 2019 10:13
Show Gist options
  • Select an option

  • Save Ilesh/44d4ed9fa3b01c8b2ff29670cc36bc9a to your computer and use it in GitHub Desktop.

Select an option

Save Ilesh/44d4ed9fa3b01c8b2ff29670cc36bc9a to your computer and use it in GitHub Desktop.
For display google ads
//
// GoogleAds.swift
//
//
// Created by Ilesh's 2018 on 18/05/19.
// Copyright © 2019 Ilesh. All rights reserved.
//
import UIKit
import GoogleMobileAds
class IPGoogleAds: NSObject {
static let shard : GoogleAds = GoogleAds()
var interstitial: GADInterstitial!
override init() {
super.init()
}
func showAds(isForce:Bool = false) -> Void {
if Global.kretriveUserData().IsAdsShow == "1" || isForce {
interstitial = GADInterstitial(adUnitID: "ca-app-pub-3008788978524384/8787765015") //ca-app-pub-3940256099942544/4411468910 <-- Testing
interstitial.delegate = self
let request = GADRequest()
interstitial.load(request)
}
}
}
extension IPGoogleAds : GADInterstitialDelegate {
/// Tells the delegate an ad request succeeded.
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
print("interstitialDidReceiveAd")
if interstitial.isReady {
interstitial.present(fromRootViewController: Global.appDelegate.window!.rootViewController!)
} else {
print("Ad wasn't ready")
}
}
/// Tells the delegate an ad request failed.
func interstitial(_ ad: GADInterstitial, didFailToReceiveAdWithError error: GADRequestError) {
print("interstitial:didFailToReceiveAdWithError: \(error.localizedDescription)")
}
/// Tells the delegate that an interstitial will be presented.
func interstitialWillPresentScreen(_ ad: GADInterstitial) {
print("interstitialWillPresentScreen")
}
/// Tells the delegate the interstitial is to be animated off the screen.
func interstitialWillDismissScreen(_ ad: GADInterstitial) {
print("interstitialWillDismissScreen")
}
/// Tells the delegate the interstitial had been animated off the screen.
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
print("interstitialDidDismissScreen")
}
/// Tells the delegate that a user click will open another app
/// (such as the App Store), backgrounding the current app.
func interstitialWillLeaveApplication(_ ad: GADInterstitial) {
print("interstitialWillLeaveApplication")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment