您如何在Swift和iOS 9中实现iAd预滚视频?
我正在尝试在我的游戏中播放一段预演iAd视频,而不在之后进行视频播放,这就是我在所看到的所有示例中看到的效果。当我开始播放预演iAd时,AV View控制器会显示,但没有播放任何内容,我进入错误案例,如下所示,表示无法播放。我要做的是在像“打开锁”这样的游戏中,如果你看视频广告,它会给你第二次机会 在我的AppDelegate.swift中,我有以下代码来准备iAd视频您如何在Swift和iOS 9中实现iAd预滚视频?,swift,ios9,iad,preroll,Swift,Ios9,Iad,Preroll,我正在尝试在我的游戏中播放一段预演iAd视频,而不在之后进行视频播放,这就是我在所看到的所有示例中看到的效果。当我开始播放预演iAd时,AV View控制器会显示,但没有播放任何内容,我进入错误案例,如下所示,表示无法播放。我要做的是在像“打开锁”这样的游戏中,如果你看视频广告,它会给你第二次机会 在我的AppDelegate.swift中,我有以下代码来准备iAd视频 func application(application: UIApplication, didFinishLaunching
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
// Override point for customization after application launch.
AVPlayerViewController.preparePrerollAds()
return true
}
然后在我的ViewController中,我有以下内容来播放广告
import AVFoundation
import iAd
//this is declared at the top
let adPlayerController = AVPlayerViewController()
//this gets called inside of a function
adPlayerController.playPrerollAdWithCompletionHandler({ (error) -> Void in
if error != nil
{
print(error)
print("Ad could not be loaded")
}
else
{
print("Ad loaded")
}
})
我也想做同样的事情,但在预演视频中失败了。现在我的bannerView有iAd,我用AdMob做视频广告来获得第二次机会 只需下载AdMob并放入您的应用程序。然后导入
import GoogleMobileAds
创建一个变量
var interstitial: GADInterstitial!
然后创建将加载并显示视频广告的func
func loadAd() {
self.interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
let request = GADRequest()
// Requests test ads on test devices.
request.testDevices = ["e23db0f2cf8d82b7b4f23ede7df2f928"]
interstitial.delegate = self
self.interstitial.loadRequest(request)
}
func showAd() {
if self.interstitial.isReady {
let vc = self.view!.window?.rootViewController
self.interstitial.presentFromRootViewController(vc)
}
}
func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
print("Video Ad did not load")
}
func interstitialDidDismissScreen(ad: GADInterstitial!) {
}
func interstitialDidReceiveAd(ad: GADInterstitial!) {
}
func interstitialWillLeaveApplication(ad: GADInterstitial!) {
}
func interstitialWillPresentScreen(ad: GADInterstitial!) {
}
func interstitialWillDismissScreen(ad: GADInterstitial!) {
}
可能的重复可能的重复