Integrate iAd pre-roll video integration in my app?

后端 未结 1 372
滥情空心
滥情空心 2020-12-22 03:09

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 \"The

相关标签:
1条回答
  • 2020-12-22 03:25

    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()
            }
        }
    

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

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

    0 讨论(0)
提交回复
热议问题