尝试使用ADMob添加插页式广告时出现错误

时间:2019-04-09 15:28:51

标签: ios swift admob

我尝试在我的应用程序中实施插页式广告。但是我的控制台出现错误。我在做什么错了?

这是我的控制台:

2019-04-09 18:23:41.943930+0300 Sozo[5332:159395] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/jonwilson/Library/Developer/CoreSimulator/Devices/75A98A4F-6B72-431C-985C-40DA88E34B57/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2019-04-09 18:23:41.944524+0300 Sozo[5332:159395] [MC] Reading from private effective user settings.
2019-04-09 18:23:41.960135+0300 Sozo[5332:159395] <Google> To get test ads on this device, set: request.testDevices = @[ kGADSimulatorID ];
2019-04-09 18:23:43.524904+0300 Sozo[5332:159622] ATS failed system trust
2019-04-09 18:23:43.524998+0300 Sozo[5332:159622] System Trust failed for [1:0x600002d9db00]
2019-04-09 18:23:43.525164+0300 Sozo[5332:159622] TIC SSL Trust Error [1:0x600002d9db00]: 3:0
2019-04-09 18:23:43.529783+0300 Sozo[5332:159622] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
2019-04-09 18:23:43.529941+0300 Sozo[5332:159622] Task <C47E5A3E-E77D-4D02-9AF5-A3018228B91D>.<0> HTTP load failed (error code: -1200 [3:-9802])
2019-04-09 18:23:43.530314+0300 Sozo[5332:159591] NSURLConnection finished with error - code -1200

我尝试在youtube上观看各种视频,但似乎没有什么适合我的问题。

var interstitial: GADInterstitial!

@IBOutlet weak var startButton: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()

    //ad ID
    interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")

    //request ad
    let request = GADRequest()
    interstitial.load(request)

    interstitial = createAndLoadInterstitial()

    interstitial.delegate = self

@IBAction func startButtonAd(_ sender: Any) {
    if interstitial.isReady {
        interstitial.present(fromRootViewController: self)
    }
}

func createAndLoadInterstitial() -> GADInterstitial {
    let interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
    interstitial.delegate = self
    interstitial.load(GADRequest())
    return interstitial
}

func interstitialDidDismissScreen(_ ad: GADInterstitial) {
    interstitial = createAndLoadInterstitial()
}

1 个答案:

答案 0 :(得分:0)

首先,如控制台中所述:

To get test ads on this device, set: request.testDevices = @[ kGADSimulatorID ];

您必须在let request = GADRequest()下方添加以下代码以获取测试广告:

request.testDevice = [kGADSimulatorID]

然后,您会发现您遇到了一些AppTransportSecurity问题,是否已按照此处的ATS配置进行操作:https://developers.google.com/admob/ios/app-transport-security

如Google文档所述,您必须禁用ATS才能接收广告而不会遇到任何麻烦。