Xcode 8中的插页式广告

时间:2017-08-09 08:16:18

标签: ios xcode firebase admob interstitial

我使用xcode创建了一个iOS应用程序,我正在使用webview,我已经实现了google admob横幅广告,但现在我还想在我的应用中显示非页内广告而不点击任何按钮,我的意思是当我的网址加载插页式广告时节目。我正在使用此代码,但无效

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日志中看不到任何错误,请帮助我,谢谢

1 个答案:

答案 0 :(得分:0)

请勿跳过将AppDelegate导入“GoogleMobileAds”并连接GADInterstitialDelegate。如果您的ID是真的,请在AppDelegate中尝试:

   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("")
}

如果出现错误,您可以在控制台中显示失败