2

我正在尝试在我的游戏中播放 Preroll iAd 视频,之后不播放视频,这就是我在我见过的所有示例中看到的方式。当我去播放 Preroll iAd 时,会显示 AV 视图控制器,但没有播放任何内容,并且我进入了如下所示的错误情况,说它无法播放。我要做的是在像“Pop The Lock”这样的游戏中完成,如果你观看视频广告,它会给你第二次机会。

在我的 AppDelegate.swift 中,我有以下代码来准备 iAd 视频。

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")
            }
        })
4

1 回答 1

0

我想做同样的事情,但前贴片视频没有成功。现在我的bannerView 有iAd,我使用AdMob 来制作视频广告以获得第二次机会。

只需下载 AdMob 并将其放入您的应用中即可。然后导入

import GoogleMobileAds

创建一个变量

var interstitial: GADInterstitial!

然后创建将加载和显示视频广告的函数。

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!) {

}
于 2016-03-13T21:41:34.357 回答