当我的 callButton 被点击时,它会响起一个电话号码,我想在调用电话之前展示我的插页式广告。我已经在“IBAction 函数广告”按钮上测试了我的广告,它可以在按钮上运行,但是当我在 callButton 函数上调用它时,它不会运行并直接调用电话。
class ProfilePageViewController: UIViewController, MFMessageComposeViewControllerDelegate, UITableViewDelegate, UIAlertViewDelegate, GADInterstitialDelegate {
@IBAction func ad(_ sender: Any) {
if self.interstitialAd.isReady {
self.interstitialAd.present(fromRootViewController: self)
}
}
@IBAction func callButton(_ sender: Any) {
if let contactopt = contact{
if let url = NSURL(string: "tel://\(contactopt)") {
// UIApplication.shared.openURL(url as URL)
UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
}
}
}
var interstitialAd: GADInterstitial!
func reloadInterstitialAd() -> GADInterstitial {
var interstitial = GADInterstitial(adUnitID: "ca-app-pub-/6966780536")
interstitial.delegate = self
interstitial.load(GADRequest())
return interstitial
}
func interstitialDidDismissScreen(ad: GADInterstitial!) {
self.interstitialAd = reloadInterstitialAd()
}
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
interstitialAd = reloadInterstitialAd()
}
override func viewDidLoad() {
self.interstitialAd = GADInterstitial(adUnitID: "ca-app-pub-/6966780536")
let request = GADRequest()
request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
self.interstitialAd.load(request)
self.interstitialAd = reloadInterstitialAd()
super.viewDidLoad()
}
最佳答案
当然是打电话了。这就是您告诉它用 UIApplication.shared.open
做的事情。
在 interstitialDidDismissScreen
中关闭广告后进行调用。
还要检查是否有要展示的广告,interstitialAd.isReady
。如果没有要展示的广告,请直接调用电话。
您还在 viewDidLoad
中执行了两次相同的操作:
// Sets up an ad
self.interstitialAd = GADInterstitial(adUnitID: "ca-app-pub-/6966780536")
let request = GADRequest()
request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
self.interstitialAd.load(request)
// Creates a new ad
self.interstitialAd = reloadInterstitialAd()
只需调用 self.interstitialAd = reloadInterstitialAd()
。
关于ios - 在 IBAction 按钮上加载插页式广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43876985/