我正在尝试将广告植入我的第一个应用程序中。我使横幅广告发挥了作用,但目前仍停留在插页式广告上。
我已在 App Delegate 和 plist 中启动它,我的代码如下所示:
import UIKit
import SpriteKit
import GameplayKit
import GoogleMobileAds
class GameViewController: UIViewController {
var interstitialAd: GADInterstitialAd?
override func viewDidLoad() {
super.viewDidLoad()
interstitialSetup()
}
func interstitialSetup() {
GADInterstitialAd.load(withAdUnitID: "ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXX", request: GADRequest(), completionHandler: { [self] ad, error in
if let error = error {
print("Failed to load interstitial ad with error: \(error.localizedDescription)")
} else {
print("Load successful.")
}
self.interstitialAd = ad
self.interstitialAd?.fullScreenContentDelegate = self
}
)
}
func interstitialPresent() {
self.interstitialAd?.present(fromRootViewController: self)
}
}
extension GameViewController: GADFullScreenContentDelegate {
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Ad did dismiss full screen content.")
}
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
print("Ad did fail to present full screen content.")
}
func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Ad did present full screen content.")
}
}
当在我的游戏场景中按下“开始按钮”节点时,当前会调用
interstitialPresent()
函数。
有人可以帮忙解决这里出了什么问题吗?
我能够解决这个问题。我的 GameViewController 在 viewDidLoad 函数中转换为 SKView,并且插页式广告无法在 SKView 中呈现,只能在 UIView 中呈现。