iAd插页式广告因错误而崩溃"在展开可选值时意外发现nil"

时间:2016-01-11 01:43:40

标签: ios swift sprite-kit iad

我的GameScene中有我的插页式广告的代码,每次他们应该被调用时,我都会在标题中看到错误:

func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
    iAdInterstitialView = SKView()
   iAdInterstitialView.frame = self.view!.bounds //This line
view?.addSubview(iAdInterstitialView)

   interstitialAd.presentInView(iAdInterstitialView)
UIViewController.prepareInterstitialAds()
}

还有其他人有这个问题并修复过吗?先感谢您。

1 个答案:

答案 0 :(得分:1)

这意味着nil中展开的值为self.view!。 你可以这样检查:

if let view = self.view {
    iAdInterstitialView.frame = view.bounds
}