2017-08-09 67 views
0

我做了Xcode的iOS应用程序,我使用的WebView,我已经实现谷歌的AdMob横幅广告,但现在我也想显示在我的应用程序的插页式广告没有点击任何按钮,我的意思是,当我的网址加载插页式广告展示768,16。我使用此代码,但不工作插页式广告在Xcode中8

interstitial = GADInterstitial(adUnitID: "") 
    let request = GADRequest() 
    // Request test ads on devices you specify. Your test device ID is printed to the console when 
    // an ad request is made. 
    request.testDevices = [ kGADSimulatorID, "2077ef9a63d2b398840261c8221a0c9b" ] 
    interstitial.load(request) 

    if interstitial.isReady { 
     interstitial.present(fromRootViewController: self) 
    } else { 
     print("Ad wasn't ready") 
    } 

和AppDelegate.m

FirebaseApp.configure() 

,但广告不显示,我看不到在Xcode中日志任何错误,请帮帮我,谢谢

回答

0

不要跳过将您的AppDelegate导入到“GoogleMobileAds”并连接GADInterstitialDelegate。而这种尝试在AppDelegate中,如果您的ID是正确的:

var interstitial: GADInterstitial! 
    var window: UIWindow? 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

    GADMobileAds.configure(withApplicationID: "yourApplicationID") 
    return true 
} 

func showInterstitial(_ notification: NSNotification) { 

    interstitial = GADInterstitial(adUnitID: "youradUnitID") 
    let request = GADRequest() 
    interstitial.delegate = self 
    // Request test ads on devices you specify. Your test device ID is printed to the console when 
    // an ad request is made. 
    //request.testDevices = [ kGADSimulatorID, "2077ef9a63d2b398840261c8221a0c9b" ] 
    interstitial.load(request) 
} 

func interstitialDidReceiveAd(_ ad: GADInterstitial) { 

    if(self.interstitial.isReady){ 
     interstitial.present(fromRootViewController: (self.window?.rootViewController)!) 

    } 
} 

func interstitialDidFail(toPresentScreen ad: GADInterstitial) { 
    NSLog("") 
} 

如果有错误,您可以显示故障控制台