2017-05-09 3 views
0

私のcallButtonをクリックすると、電話番号が鳴り、コールが行われる前にインタースティシャル広告が表示されます。私は "IBAction function ad"ボタンで広告をテストしましたが、それはボタン上で動作しますが、callButton funcで呼び出すと機能しなくなり、電話をかけることになります。IBActionボタンのインタースティシャル広告を読み込みます。

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() 

} 

}

答えて

1

もちろん、電話をかけます。それはあなたが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()を呼び出します。

+0

私はそれがフルページの広告を表示する方法を「IBAction機能広告」を残し提案、およびinterstitialDidDismissScreen機能で私callButton関数を呼び出していますか? –

+0

@hghg申し訳ありませんが、私はあなたが何を求めているのか分かりません。 –

0

私はあなたの問題は、間質にpresentメソッドの同期に関係していると信じています。私は実装が何であるかはわかりませんが、広告のプレゼンテーションが呼び出されたスレッドをブロックしないようです。 GADInterstitialDelegateを実装して、広告が表示されたときにイベントを取得し、そこから電話をかけてください。

0

これを試してみてください:

GADInterstitialは、1時間の使用目的です。つまり、 インタースティシャルが表示されたら、hasBeenUsedはtrueを返し、インタースティシャル は別の広告を読み込むことができません。別のインタースティシャルをリクエストするには、 に新しいGADInterstitialオブジェクトを作成する必要があります。上記のようなベストプラクティス は、作成を処理するヘルパーメソッドを持ち、 インタースティシャルを読み込むことです。

func createAndLoadInterstitial() -> GADInterstitial { 
    var interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910") 
    interstitial.delegate = self 
    interstitial.load(GADRequest()) 
    return interstitial 
} 

func interstitialDidDismissScreen(_ ad: GADInterstitial) { 
    interstitial = createAndLoadInterstitial() 
} 

@IBAction func ad(_ sender: Any) { 
    if self.interstitialAd.isReady { 
     self.interstitialAd.present(fromRootViewController: self) 
    } 
} 
関連する問題