2016-09-24 38 views
-1

我在这一行中遇到错误ad.adUnitID = "ca-app-pub-1469592343938512/3581855984",我不知道如何修复它。GAD间接错误

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()。 =为的GADInterstitial建议的生命周期是预先加载它,当应用程序启动时,您已在viewDidLoad中做正确

正确的代码

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

语法不正确。请参阅Daniel提供的链接 –