简体   繁体   中英

Admob banner Thread 1 error

I would like to show an adMob banner. I think I've configured adMob correctly but when I launch the app it crashes giving the famous error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value . I don't know what I am doing wrong. The error is on the line 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.
    }

Make sure banner1 is referenced correctly from your storyboard to the ViewController. Also make sure the class of banner1 in storyboard is assigned to GADBannerView.

将类设置为视图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM