2016-09-24 21 views
-1

この行にエラーが表示されますad.adUnitID = "ca-app-pub-1469592343938512/3581855984"と私はそれを修正する方法がわかりません。GADInterststial error

import UIKit 
import GoogleMobileAds 

class ViewController: UIViewController, GADBannerViewDelegate { 

@IBOutlet var BannerView: GADBannerView! 

var interstitial: GADInterstitial! 

override func viewDidLoad() { 
    super.viewDidLoad() 

    self.interstitial = self.createAndLoadAD() 

    let request = GADRequest() 
    request.testDevices = [kGADSimulatorID] 
    BannerView.delegate = self 
    BannerView.adUnitID = "ca-app-pub-1469592343938512/2613153588" 
    BannerView.rootViewController = self 
    BannerView.loadRequest(request) 
} 

func createAndLoadAD() -> GADInterstitial{ 

    var ad = GADInterstitial() 
    ad.adUnitID = "ca-app-pub-1469592343938512/3581855984" 

    var request = GADRequest() 

    request.testDevices = ["ca-app-pub-1469592343938512/3581855984"] 

    ad.loadRequest(request) 
    return ad 
} 

@IBAction func ADButton(sender: AnyObject) { 

    if (self.interstitial.isReady) { 
     self.interstitial.presentFromRootViewController(self) 
     self.interstitial = self.createAndLoadAD() 
    } 
} 

enter image description here

+0

* "この行にはエラーがあります" *。エラーは何ですか? –

+0

'request.testDevices = [" ca-app-pub-1469592343938512/3581855984 "]'これは正しくありません。 –

+0

この例を確認してください。各行はコメントアウトされています:http://stackoverflow.com/a/36389999/2108547 –

答えて

0

ADButtonの内側ラインcreateAndLoadAD()を削除します。アプリは、あなたがのviewDidLoadで正しく行われている、起動時に は= GADInterstitialのために推奨されるライフサイクルがそれをプリロードすることです

正しいコードは

if interstitial.isReady { 
    interstitial.presentFromRootViewController(self) 
    } else { 
    print("Ad wasn't ready") 
    } 

は完全例えばhttps://firebase.google.com/docs/admob/ios/interstitialhttps://github.com/googleads/googleads-mobile-ios-examples/tree/master/Swift/admob/InterstitialExample/InterstitialExampleを参照してくださいです。

これで問題が解決しない場合は、親切にもあなたのログを共有してください

+0

私の質問が更新されました。 –

+1

構文が正しくありません。ダニエルによって与えられたリンクを参照してください –