从带有分段 fault:11 错误的 Firebase 添加 AdMob

Adding AdMob from Firebase with Segmentation fault:11 error

有一个关于 Command failed due to signal: Segmentation fault: 11 的问题,但没有答案适用于我的情况。

我正在使用 Swift3、Xcode 8.0 将 AdMob 添加到 Firebase 并收到此错误:

错误:

1.  While loading members for 'CategoryVC' at <invalid loc>
2.  While deserializing decl #92 (PATTERN_BINDING_DECL)
3.  While deserializing decl #3 (VAR_DECL)

Command failed due to signal: Segmentation fault: 11

代码:

import UIKit
import Firebase
import GoogleMobileAds

 class ViewController: UIViewController {

 @IBOutlet weak var bannerView: GADBannerView!

  override func viewDidLoad() {
    super.viewDidLoad()

    bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
    bannerView.rootViewController = self
    bannerView.load(GADRequest())
 }

}



 import UIKit
 import Firebase
 import GoogleMobileAds

  class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    FIRApp.configure()

    GADMobileAds.configure(withApplicationID: "ca-app-pub-xxxxxxxxxx")

    return true

    }
 }

viewDidLoad() 中的代码更改为:-

class ViewController: UIViewController, GADBannerViewDelegate {

override func viewDidLoad() {
        super.viewDidLoad()

    let request                     = GADRequest()
    bannerView.alpha              = 1
    bannerView.adSize             = kGADAdSizeSmartBannerLandscape
    bannerView.delegate           = self
    bannerView.rootViewController = self
    request.testDevices             = [kGADSimulatorID]
    bannerView.adUnitID           = "ca-app-pub-3940256099942544/2934735716"
    bannerView.load(request)

 }

还要确保您已在情节提要中将 bannerView 的自定义 class 也声明为 GADBannerView

我终于明白了!安装 Firebase/Admob 并添加 bannerView 代码后出现所有问题。 #1 中提到的 CategoryVC 是我添加的唯一 ViewController bannerView。因为当我使用 terminal 安装 pod file 时,它提到我的 Cocoapods 不是最新的。所以我更新了 Cocoapods 看看有没有好运。

步骤:

  1. 打开你的终端。输入:

    sudo gem install cocoapods
    
  2. 导航到您的项目文件夹并打开您的 pod 文件。必要时进行更改,或者保存并退出。

  3. 运行:

    pod update
    

它可能不适用于您的情况。祝你好运!

查看 Google AdMob 提供的示例项目后,解决方法是添加行 use_frameworks!到 pod 文件依赖列表。

此后,该应用程序需要更少的导入 运行,并且此后一直没有构建失败。