在我的应用中集成iAd前贴片视频集成? [英] Integrate iAd pre-roll video integration in my app?

查看:112
本文介绍了在我的应用中集成iAd前贴片视频集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将iAd Pre-Roll视频广告集成到我的应用程序中。当我运行此应用程序时,它给了我这个错误:

I want to integrate an iAd Pre-Roll video Ad to my application. When I run this application, it gives me this error:


Domain = ADErrorDomain Code = 0操作无法完成。( ADErrorDomain错误0。)

Domain=ADErrorDomain Code=0 "The operation couldn’t be completed. (ADErrorDomain error 0.)

我想知道这段代码是否正确或错误。感谢您的帮助。

I want to know if this code is correct or incorrect. Thanks for your help.

import UIKit
import MediaPlayer
import iAd

class ViewController: UIViewController {

    var moviePlayer : MPMoviePlayerController!

    override func viewDidLoad() {
        super.viewDidLoad()



        let url = NSBundle.mainBundle().URLForResource("intro", withExtension: "mp4")
        moviePlayer = MPMoviePlayerController(contentURL: url)

        moviePlayer!.view.frame = view.frame

        moviePlayer!.prepareToPlay()
        view.addSubview(moviePlayer!.view!)


        moviePlayer.playPrerollAdWithCompletionHandler { (error) -> Void in
            NSLog("\(error)")
            self.moviePlayer.play()
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

这是一个我修改过的App Delegate函数:

This is one of my modified App Delegate function:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        MPMoviePlayerController.preparePrerollAds()
        return true
    }


推荐答案

您尝试在应用程序有任何时间下载之前显示您的预滚动视频广告。几秒钟后触发 moviePlayer.playPrerollAdWithCompletionHandler 或将视频移至介绍中的稍后位置,以便您的应用程序有时间下载广告。检查我的示例:

You're trying to display your Pre-Roll Video Ad before your application has had any time to download it. Fire your moviePlayer.playPrerollAdWithCompletionHandler after a few seconds or move the video to a later point in your intro so your application has time to download the ad. Check my example:

import UIKit
import MediaPlayer
import iAd

class ViewController: UIViewController {
    // Create our MPMoviePlayerController
    var moviePlayer = MPMoviePlayerController()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Preload ad
        MPMoviePlayerController.preparePrerollAds()

        // Setup our MPMoviePlayerController
        moviePlayer.view.frame = self.view.bounds
        moviePlayer.setFullscreen(true, animated: true)
    }

    @IBAction func playVideoButton(sender: AnyObject) {
        // Add our MPMoviePlayerController to our view
        self.view.addSubview(moviePlayer.view)

        // Path of video you want to play
        let videoURL = NSBundle.mainBundle().URLForResource("videoName", withExtension:"MOV")

        // Set the contents of our MPMoviePlayerController to our video path
        moviePlayer.contentURL = videoURL

        // Prepare our movie for playback
        moviePlayer.prepareToPlay()

        // Play our video with a prerolled ad
        moviePlayer.playPrerollAdWithCompletionHandler { (error) -> Void in
            if (error) != nil {
                NSLog("\(error)")
            }
            self.moviePlayer.play()
        }
    }

点击 UIButton playVideoButton 应用程序启动后几秒钟将播放预先录制的视频广告,然后播放所需的视频。

Tapping the UIButton playVideoButton a few seconds after application launch will play the prerolled video advertisement and then the desired video.

另外,如果你在您的设备上重新测试,请转到设置>开发者>填充率>,并确保将其设置为100%。

Also, If you're testing on your device go to Settings>Developer>Fill Rate> and make sure it is set to 100%.

这篇关于在我的应用中集成iAd前贴片视频集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆