gpt4 book ai didi

ios - admob横幅广告在游戏场景中大约一分钟后显示广告忽略bannerAd.isHidden xcode 8

转载 作者:行者123 更新时间:2023-11-30 12:48:04 36 4
gpt4 key购买 nike

我的游戏有两种横幅广告类型,顶部横幅和底部横幅,顶部仅在游戏场景中显示,底部仅在主菜单中显示它可以工作,除了在游戏过程中大约一分钟后由于某种原因,我的顶部横幅隐藏,底部显示此是我的代码

`

    var bannerView = GADBannerView(adSize: kGADAdSizeSmartBannerLandscape)
var bannerViewPortrait = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)

override func viewDidLoad() {
super.viewDidLoad()

initializeAds()
initializePortraitAds()

NotificationCenter.default.addObserver(self, selector: #selector(showBanner), name: Notification.Name("showBanner"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(hideBanner), name: Notification.Name("hideBanner"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(showPortraitBanner), name: Notification.Name("showPortraitBanner"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(hidePortraitBanner), name: Notification.Name("hidePortraitBanner"), object: nil)



if let view = self.view as! SKView? {
if let scene = MainMenuScene(fileNamed: "MainMenu") {
scene.scaleMode = .aspectFill
view.presentScene(scene)
}

view.ignoresSiblingOrder = true

view.showsFPS = true
view.showsNodeCount = true
view.showsPhysics = false
}
}

func showBanner() {
bannerView.isHidden = false
}
func showPortraitBanner() {
bannerViewPortrait.isHidden = false
}
func hidePortraitBanner() {
bannerViewPortrait.isHidden = true
}
func hideBanner() {
bannerView.isHidden = true
}

func initializeAds() {
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
bannerView.isHidden = true

bannerView.delegate = self

bannerView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
bannerView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
bannerView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true

bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
bannerView.rootViewController = self
bannerView.load(GADRequest())
}
func initializePortraitAds() {
bannerViewPortrait.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerViewPortrait)
bannerViewPortrait.isHidden = true

bannerViewPortrait.delegate = self

bannerViewPortrait.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
bannerViewPortrait.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
bannerViewPortrait.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true

bannerViewPortrait.adUnitID = "ca-app-pub-3940256099942544/2934735716"
bannerViewPortrait.rootViewController = self
bannerViewPortrait.load(GADRequest())

}

func adViewDidReceiveAd(_ bannerView: GADBannerView) {
hideBanner()
showPortraitBanner()
}

func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) {
hideBanner()
hidePortraitBanner()
print("Error: \(error.localizedDescription)")
}`

和我的游戏场景`

 override func didMove(to view: SKView) {

NotificationCenter.default.post(name: Notification.Name("showBanner"), object: nil)
NotificationCenter.default.post(name: Notification.Name("hidePortraitBanner"), object: nil)}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
NotificationCenter.default.post(name: Notification.Name("showBanner"), object: nil)
NotificationCenter.default.post(name: Notification.Name("hidePortraitBanner"), object: nil)}`

请原谅我的凌乱代码,我刚刚开始学习

@Jake T.你说得完全正确,不需要两个bannerView,这是我的尝试,只有一个变量,正如你从我的代码中看到的那样,我是一个初学者

`

   var bannerView = GADBannerView(adSize: kGADAdSizeSmartBannerLandscape)

override func viewDidLoad() {
super.viewDidLoad()

initializeAds()

NotificationCenter.default.addObserver(self, selector: #selector(topBanner), name: Notification.Name("topBanner"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(bottomBanner), name: Notification.Name("bottomBanner"), object: nil)



if let view = self.view as! SKView? {
if let scene = MainMenuScene(fileNamed: "MainMenu") {
scene.scaleMode = .aspectFill
view.presentScene(scene)
}

view.ignoresSiblingOrder = true

view.showsFPS = true
view.showsNodeCount = true
view.showsPhysics = false
}
}

func topBanner() {
bannerView.adSize = kGADAdSizeSmartBannerLandscape
bannerView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
bannerView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
bannerView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true


}

func bottomBanner() {
bannerView.adSize = kGADAdSizeSmartBannerPortrait
bannerView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
bannerView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
bannerView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true

}

func initializeAds() {
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
bannerView.isHidden = true

bannerView.delegate = self

bannerView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
bannerView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
bannerView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true

bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
bannerView.rootViewController = self
bannerView.load(GADRequest())
}


func adViewDidReceiveAd(_ bannerView: GADBannerView) {
bannerView.isHidden = false

}

func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) {

bannerView.isHidden = true
print("Error: \(error.localizedDescription)")
}

`

最佳答案

func adViewDidReceiveAd(_bannerView: GADBannerView) {
隐藏横幅()
显示肖像横幅()
}

这会隐藏顶部横幅,并显示底部横幅。编辑:我不能 100% 确定这是您的错误根源,因为您没有在任何地方显示如何调用此方法,但这很可能是您的错误。您可能只想将 showPortraitBanner()hidePortraitBanner()

交换

此外,您的横幅有奇怪的名称。您应该将名称更改为“topBanner”和“bottomBanner”或其他名称。纵向与横向就像垂直或水平握住手机。这意味着,您至少对其中之一使用了错误的横幅,除非您实际上仅在正确的方向上显示这些横幅。如果您的游戏仅采用单一方向,您应该更改放在这里的前两行之一,以便它们都是正确的方向。

关于ios - admob横幅广告在游戏场景中大约一分钟后显示广告忽略bannerAd.isHidden xcode 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41368820/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com