Admob横幅广告线程1错误

时间:2018-08-22 15:17:48

标签: ios swift admob

我想展示一个adMob横幅。我认为我已经正确配置了adMob,但是当我启动该应用程序时,它崩溃并给出著名的错误:线程1:致命错误:在展开一个Optional值时意外发现nil 。我不知道我在做什么错。错误出现在banner1.adUnitID = "ca-app-pub-1314395885924826/98794********" ViewController.swift行:

import UIKit
import Foundation
import MessageUI
import Firebase
import GoogleMobileAds

class ViewController: UIViewController, MFMailComposeViewControllerDelegate {

    @IBOutlet weak var banner1: GADBannerView!

    override func viewDidLoad() {

        banner1.adUnitID = "ca-app-pub-1314395885924826/98794********"    //Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
        banner1.rootViewController = self
        banner1.load(GADRequest())
        // Do any additional setup after loading the view, typically from a nib.
    }

1 个答案:

答案 0 :(得分:0)

确保从您的情节提要中正确引用banner1到ViewController。此外,还要确保将情节提要中的banner1类分配给GADBannerView。

Set class to the view