我正在使用AdMob实现间隙广告,但它没有显示。
这是我的课,我想在那里实现间质广告。
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)
}
}发布于 2016-02-12 09:07:19
为类添加委托函数(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()发布于 2016-02-15 06:04:07
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)
}
//-------------------------第二步:现在,无论在哪里,或者在任何veiwController中,您都希望显示间隙广告,然后在该文件中添加这些内容。
let App = UIApplication.sharedApplication().delegate as! AppDelegate
App.gViewController = self;
App.showAdmobInterstitial()
By this way we can call now interstitial ads easily.https://stackoverflow.com/questions/35357479
复制相似问题