如何让我的插页式 adMob 广告超时显示按钮被点击
how can I make my interstitial adMob ad show overtime a button is clicked
现在它只显示整页广告一次。当我返回并再次按下按钮时,它没有显示。我希望它显示加班我的按钮被点击。我已将我的 AdMob 连接到我的 Firebase 项目。
class FirstViewController: UIViewController, UIAlertViewDelegate {
var interstitial: GADInterstitial!
@IBAction func loadAd(_ sender: Any) {
if (interstitial.isReady){
interstitial.present(fromRootViewController: self)
}
}
override func viewDidLoad() {
interstitial = GADInterstitial(adUnitID: "ca-app-pub-11111111/9758796532")
let request = GADRequest()
interstitial.load(request)
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
您每次都需要创建 GAD 请求。
GADInterstitial is a one time use object. That means once an
interstitial is shown, hasBeenUsed returns true and the interstitial
can't be used to load another ad. To request another interstitial,
you'll need to create a new GADInterstitial object. The best practice,
as shown above, is to have a helper method to handle creating and
loading an interstitial.
@IBAction func loadAd(_ sender: Any) {
interstitial = GADInterstitial(adUnitID: "ca-app-pub-11111111/9758796532")
interstitial.delegate = self
let request = GADRequest()
interstitial.load(request)
}
加载成功后,您需要在委托方法中呈现
optional func interstitialDidReceiveAd(_ ad: GADInterstitial!){
if (interstitial.isReady){
interstitial.present(fromRootViewController: self)
}
}
optional func interstitialWillDismissScreen(_ ad: GADInterstitial!){
interstitial.delegate = nil
interstitial = nil
}
optional func interstitialDidFail(toPresentScreen ad: GADInterstitial!){
interstitial.delegate = nil
interstitial = nil
}
关闭插页式广告时,我们必须为下一个插页式广告创建并发出加载请求。
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
interstitial = createAndLoadInterstitial()
}
分配另一个插页式广告的最佳位置是在 GADInterstitialDelegate 的 interstitialDidDismissScreen: 方法中,以便在前一个插页式广告关闭后立即开始加载下一个插页式广告。您甚至可以考虑将插页式初始化分解为它自己的辅助方法:
现在它只显示整页广告一次。当我返回并再次按下按钮时,它没有显示。我希望它显示加班我的按钮被点击。我已将我的 AdMob 连接到我的 Firebase 项目。
class FirstViewController: UIViewController, UIAlertViewDelegate {
var interstitial: GADInterstitial!
@IBAction func loadAd(_ sender: Any) {
if (interstitial.isReady){
interstitial.present(fromRootViewController: self)
}
}
override func viewDidLoad() {
interstitial = GADInterstitial(adUnitID: "ca-app-pub-11111111/9758796532")
let request = GADRequest()
interstitial.load(request)
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
您每次都需要创建 GAD 请求。
GADInterstitial is a one time use object. That means once an interstitial is shown, hasBeenUsed returns true and the interstitial can't be used to load another ad. To request another interstitial, you'll need to create a new GADInterstitial object. The best practice, as shown above, is to have a helper method to handle creating and loading an interstitial.
@IBAction func loadAd(_ sender: Any) {
interstitial = GADInterstitial(adUnitID: "ca-app-pub-11111111/9758796532")
interstitial.delegate = self
let request = GADRequest()
interstitial.load(request)
}
加载成功后,您需要在委托方法中呈现
optional func interstitialDidReceiveAd(_ ad: GADInterstitial!){
if (interstitial.isReady){
interstitial.present(fromRootViewController: self)
}
}
optional func interstitialWillDismissScreen(_ ad: GADInterstitial!){
interstitial.delegate = nil
interstitial = nil
}
optional func interstitialDidFail(toPresentScreen ad: GADInterstitial!){
interstitial.delegate = nil
interstitial = nil
}
关闭插页式广告时,我们必须为下一个插页式广告创建并发出加载请求。
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
interstitial = createAndLoadInterstitial()
}
分配另一个插页式广告的最佳位置是在 GADInterstitialDelegate 的 interstitialDidDismissScreen: 方法中,以便在前一个插页式广告关闭后立即开始加载下一个插页式广告。您甚至可以考虑将插页式初始化分解为它自己的辅助方法: