我想添加Google移动非页内广告,但我收到了错误消息。如何添加Google非页内广告?
这是我到目前为止所拥有的:
var interstitial: GADInterstitial!
func createAndLoadAd() -> GADInterstitial
{
var ad = GADInterstitial()
ad.adUnitID = "ca-app-pub-5378899862041789/8532100959"
var request = GADRequest()
ad.loadRequest(request)
return ad
}
答案 0 :(得分:3)
插页式广告代码:
导入GoogleMobileAds
框架并将代理设置为查看:
import GoogleMobileAds
class ViewController: UIViewController, GADInterstitialDelegate
宣言:
var interstitial:GADInterstitial?
功能:
//Interstitial func
func createAndLoadInterstitial()->GADInterstitial {
var interstitial = GADInterstitial(adUnitID: "ca-app-pub-5378899862041789/8532100959")
interstitial.delegate = self
interstitial.loadRequest(GADRequest())
return interstitial
}
功能调用:
interstitial = createAndLoadInterstitial()
添加委托方法以加载广告。
添加SDK需要的其他框架
SDK取决于以下iOS开发框架,这些框架可能尚未成为您项目的一部分:
AdSupport
AudioToolbox
AVFoundation
CoreGraphics
CoreMedia
CoreTelephony
EventKit
EventKitUI
MessageUI
StoreKit
SystemConfiguration