我使用spritekit开发游戏,并按照谷歌提供的文档实施admob插页式广告。在模拟器中一切正常,广告在正确的时间按预期呈现全屏。问题是,当我在iPhone 6s中运行时,广告不会填满整个屏幕,只是黑屏上的一小部分。我在gameviewController上实现了所有的admob代码,并使用观察者在gameScene中调用它。
类GameViewController:UIViewController {
var interstitial: GADInterstitial!
override func viewDidLoad() {
super.viewDidLoad()
interstitial = createAndLoadInterstitial()
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.showIntersticialAd), name: Notification.Name("showIntersticialAd"), object: nil)
if let view = self.view as! SKView? {
let scene = MenuScene(size: view.bounds.size)
scene.scaleMode = .aspectFill
view.presentScene(scene)
view.ignoresSiblingOrder = true
view.showsFPS = false
view.showsNodeCount = false
}
}
@objc func showIntersticialAd() {
if interstitial.isReady {
interstitial.present(fromRootViewController: self)
} else {
print("Ad not ready")
}
}
}
扩展GameViewController:GADInterstitialDelegate {
func createAndLoadInterstitial() -> GADInterstitial {
let interstitial = GADInterstitial(adUnitID: "ca-app-pub-4828696079960529/6898313363")
interstitial.delegate = self
interstitial.load(GADRequest())
return interstitial
}
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
interstitial = createAndLoadInterstitial()
}
}
我在互联网和admob文档中搜索了很多,但没有弄清楚为什么会这样。
答案 0 :(得分:-2)
@objc func showIntertialAds() {
if !interstitial.isReady{
interstitial.load(GADRequest())
} if interstitial.isReady {
interstitial.present(fromRootViewController:(UIApplication.shared.keyWindow?.rootViewController)!)
}
}