首页 > 解决方案 > AdMob 插页式广告开始时应用崩溃

问题描述

我最近将我的应用程序上传到 App Store,但我发现了一个错误。每次插页式广告 (AdMob) 开始时,我的程序都会崩溃,我不知道为什么。当我从 Xcode 运行程序时,它永远不会崩溃。

import GoogleMobileAds

首先,我当然已经导入了这个。

也将此添加到我的课程中

GADInterstitialDelegate

在 viewDidLoad() 里面我添加了这个:

    interstitial = GADInterstitial(adUnitID: "AD-UNIT-ID")
    let request = GADRequest()

    request.testDevices = [ kGADSimulatorID] //Should this be removed now when the app is on App Store?
    interstitial.load(request)

    interstitial.delegate = self

再往下,我将此代码添加到我的保存按钮中:

                           //Advertisement test
                                if self.interstitial.isReady
                                {
                                    self.interstitial.present(fromRootViewController: self)
                                }
                                else
                                {
                                    print("Advertisement is not ready!")

                                    self.performSegue(withIdentifier: "History", sender: self)
                                }

最后我有这个:

    //Advertisement will dismiss from the screen
func interstitialDidDismissScreen(_ ad: GADInterstitial)
{
        self.performSegue(withIdentifier: "History", sender: self)
}

我该如何解决这个问题?每次我按下那个“保存按钮”时它都会崩溃,屏幕变黑然后轰隆隆,崩溃。

因此,当我从我的 Xcode 项目中运行它之前,它从未崩溃过,但是当我在 TestFlight 和 App Store 中时,它每次都会崩溃!

标签: iosswiftadmobapp-storeinterstitial

解决方案


推荐阅读