2016-02-12 3 views
1

Я реализую межстраничные объявления, используя материал AdMob, но он не отображается.Как реализовать межстраничные объявления с помощью AdMob в iOS с Swift?

Это мой класс, где я хочу реализовать межстраничные объявления.

import UIKit 
import GoogleMobileAds 

class SearchNew: UIViewController{ 

    var interstitial: GADInterstitial! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     self.interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910") 

     let request = GADRequest() 
     request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"] 
     self.interstitial.loadRequest(request) 

     self.showAd() 
    } 

    func showAd() { 
     if self.interstitial.isReady { 
      self.interstitial.presentFromRootViewController(self) 
     } 
    } 
+1

Даже я перечислил этот сайт на https://developers.google.com/admob/ios/interstitial, но не получал межстраничные объявления в своем приложении. –

ответ

0

Добавить функцию делегата (GADInterstitialDelegate) для вашего класса.

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate, GADInterstitialDelegate { 

    var mInterstitial: GADInterstitial! 
    var gViewController: UIViewController? 

Вызов loadRequest, он стреляет interstitialDidReceiveAd когда объявления готовые показать

func showAdmobInterstitial() 
    { 
      self.mInterstitial = GADInterstitial.init(adUnitID:kGoogleFullScreenAppUnitID) 

      mInterstitial.delegate = self 
      let Request = GADRequest() 
      Request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"] 
      mInterstitial.loadRequest(Request) 
    } 

    func interstitialDidReceiveAd(ad: GADInterstitial!) 
    { 
     ad.presentFromRootViewController(self.gViewController) 
    } 

Вызов showAdmobInterstitial из любого ViewController

  let App = UIApplication.sharedApplication().delegate as! AppDelegate 
      App.gViewController = self; 
      App.showAdmobInterstitial() 
+1

Спасибо ... У меня есть это, и теперь в моем приложении отображаются межстраничные объявления. Теперь я понял это. –

1
In this way I did this admob Interstitial ads task 

import UIKit 
import GoogleMobileAds 

//-------Interstitial adds-------- 
Step 1: You need to add this stuff in side your AppDelegate.swift file 

@UIApplicationMain 
Delegate: UIResponder, UIApplicationDelegate,GADInterstitialDelegate { 

    var gViewController: UIViewController? 

    var window: UIWindow? 


func showAdmobInterstitial() 
    { 
     let kGoogleFullScreenAppUnitID = "ca-app-pub-3940256099942544/4411468910"; 
     self.mInterstitial = GADInterstitial.init(adUnitID:kGoogleFullScreenAppUnitID) 

     mInterstitial.delegate = self 
     let Request = GADRequest() 
     Request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"] 
     mInterstitial.loadRequest(Request) 
    } 

    func interstitialDidReceiveAd(ad: GADInterstitial!) 
    { 
     ad.presentFromRootViewController(self.gViewController) 
    } 
//------------------------- 

Шаг 2: Теперь, когда когда-либо или в любом veiwController вы хотите показать межстраничные объявления, а затем добавить этот материал в этот файл.

let App = UIApplication.sharedApplication().delegate as! AppDelegate 
      App.gViewController = self; 
      App.showAdmobInterstitial() 

By this way we can call now interstitial ads easily. 
Смежные вопросы