无法转换“URLRequest”类型的参数?预期参数类型'GADRequest ??'

时间:2018-03-22 01:49:47

标签: swift admob

我无法在应用程序中确定此错误的原因。我错过了一些声明吗?这里有一个 Screenshot from Xcode.

这是我的代码:

import UIKit
import AVFoundation
import Firebase
import GoogleMobileAds

class Page1: UIViewController, AVAudioPlayerDelegate, GADInterstitialDelegate, UIAlertViewDelegate {
    var interstitial: GADInterstitial!
    var counter: Int = 0

    @IBOutlet weak var scrollView: UIScrollView!
    @IBOutlet weak var pageControl: UIPageControl!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "6splash.png")!)

        interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
        let request = GADRequest()

        request.testDevices = [ kGADSimulatorID, "2077ef9a63d2b398840261c8221a0c9b" ]
        interstitial.load(request)
    }

    //Interstitial button actions
    @IBAction func playAgain(_ sender: Any) {
        if counter % 15 == 0 {
            if interstitial?.isReady != nil {
                interstitial?.present(fromRootViewController: self)
            }
            else {
            }
        }
        counter += 1
    }

    func createAndLoadInterstitial() {
        interstitial = GADInterstitial(adUnitID: "ca-app-pub-6626761084276338/7997080801")
        interstitial?.delegate = self
        let request = GADRequest()
        interstitial?.loadRequest(request as? URLRequest ?? URLRequest())
    }

    // MARK: GADInterstitialDelegate implementation
    func interstitial(_ interstitial: GADInterstitial, didFailToReceiveAdWithError error: GADRequestError) {
        print("interstitialDidFailToReceiveAdWithError: \(error.localizedDescription)")
    }

    func interstitialDidDismissScreen(_ interstitial: GADInterstitial) {
        print("interstitialDidDismissScreen")
        createAndLoadInterstitial()
    }

}

我以前主要使用Objective-C进行编码,而且我是Swift的新手。任何帮助将不胜感激。

0 个答案:

没有答案