【问题标题】:Interstitial Ads In Xcode 8Xcode 8 中的插页式广告
【发布时间】:2017-08-09 08:16:18
【问题描述】:

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

【问题讨论】:

    标签: ios xcode firebase admob interstitial


    【解决方案1】:

    不要跳过将您的 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("")
    }
    

    如果有错误可以在控制台显示失败

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      相关资源
      最近更新 更多