Swift 加载多个谷歌间隙广告导致应用程序崩溃
我正在加载30多个间隙广告,我的应用程序由于内存问题而崩溃。我尝试将它们加载到视图中,但仍然存在相同的问题。我见过很多应用程序都有大量的间隙广告。我怎样才能在不出现内存问题的情况下加载很多广告呢Swift 加载多个谷歌间隙广告导致应用程序崩溃,swift,admob,Swift,Admob,我正在加载30多个间隙广告,我的应用程序由于内存问题而崩溃。我尝试将它们加载到视图中,但仍然存在相同的问题。我见过很多应用程序都有大量的间隙广告。我怎样才能在不出现内存问题的情况下加载很多广告呢 func loadAds(){ interstitial = GADInterstitial(adUnitID: "") let req = GADRequest() interstitial.loadRequest(req) interstitial2 = GADI
func loadAds(){
interstitial = GADInterstitial(adUnitID: "")
let req = GADRequest()
interstitial.loadRequest(req)
interstitial2 = GADInterstitial(adUnitID: "")
let reqq = GADRequest()
interstitial2.loadRequest(reqq)
interstitial3 = GADInterstitial(adUnitID: "")
/// 30 more interstitial ads
}
来自我的调试器的消息。。。
“spritekitGame[2908:5497]收到内存警告。
来自调试器的消息:由于内存问题而终止“这不是使用AdMob间隙的方式。您应该只创建一个
var
来存储您的填隙数据
创建间隙并请求一则广告。一旦你展示了该广告并且该广告已被撤销,你就请求另一则广告。听其委托方法,了解其何时被撤销
例如:
import UIKit
import GoogleMobileAds // Import AdMob
class ViewController: UIViewController, GADInterstitialDelegate { // Delegate
// Create variable
var myInterstitial: GADInterstitial!
override func viewDidLoad() {
super.viewDidLoad()
loadAd() // Load the ad
}
func loadAd() {
myInterstitial = GADInterstitial(adUnitID: "your_admob_id") // Create ad
myInterstitial.delegate = self // Set delegate
myInterstitial.loadRequest(GADRequest()) // Request ad
}
func showAd() { // Call this func when you want to show an ad
if myInterstitial.isReady { // Check to see if interstitial has an ad and is ready to be displayed
myInterstitial.presentFromRootViewController(self) // Present the ad
}
else {
print("Ad not ready")
}
}
func interstitialDidDismissScreen(ad: GADInterstitial!) {
// The ad has been dismissed from the screen by the user
// Request a new ad for the next time you want to show one
loadAd() // Load a new ad
}
有关更多信息,请参阅谷歌的文档。如何像每个中间id一样继续加载广告?@BOB你应该只有一个中间id,但我不能多次加载。谷歌上就是这么说的documentation@BOB他们说你不能多次使用同一个物体。当在
InterstitualDidDismissScreen
中调用loadAd()
时,我们正在创建一个全新的GadInterstitual
,使用MyInterstitual=GadInterstitutial(adUnitID:“您的admob\u id”)
。感谢您的详细说明,我现在就明白了这是如何与承认一起工作的。