在Swift中关闭插页式广告时出现的问题

时间:2019-11-30 15:47:40

标签: swift admob ads interstitial

我设法将非页内广告添加到我的文字冒险应用程序中,但是由于某种原因关闭广告后,它会重新启动故事并将您带到最开始,而不是让您停留在在广告打开之前放置的位置。目前,我尝试为广告创建功能,以便在按下按钮时在特定位置调用广告,

override func viewDidLoad() {
super.viewDidLoad()

interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
interstitial.delegate = self
let request = GADRequest()
interstitial.load(request)

}

func forAds() {
  if (interstitial.isReady) {
    interstitial.present(fromRootViewController: self)
    interstitial = createAds()
    audioPlayer.pause()
  }
  else {
    print("Ad not ready")
  }
}

func createAds() -> GADInterstitial {

let inter = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
inter.load(GADRequest())
return inter

}

然后我这样称呼广告:

else if sender.tag == 1  && storyIndex == 6 {
    storyTextView.text = storyTwo // new text for the plot area
    topButton.setTitle(answerGateA, for: .normal) // new title for this button
    bottomButton.setTitle(answerGateB, for: .normal) // new title for this button
    storyIndex = 8   // page number                       
    forAds() // my ad function like written above
}

我假设答案与广告事件有关,但到目前为止,我还没有碰到像这样的事件:

func interstitialDidDismissScreen(_ ad: GADInterstitial) {
}

此外,加载加载项时,我会收到此错误:

同步远程对象代理返回错误:Error Domain = NSCocoaErrorDomain代码= 4099“在名为com.apple.commcenter.coretelephony.xpc的pid 0上的服务连接无效。 UserInfo = {NSDebugDescription =在pid 0上名为com.apple.commcenter.coretelephony.xpc的服务连接已无效。}

如果可以的话请提供帮助-谢谢!

0 个答案:

没有答案