Search code examples
swiftmpmovieplayercontrolleriad

notification when MPMoviePlayerController.preparePrerollAds() is ready


I've successfully implemented preroll video ads as per this post.

This tutorial works find with a 100% fill rate in simulator but isn't going as planned now my app is live.

Is it possible to get a notification that the prerollad is ready?

What I want to do is only have the button visible if an ad is ready to load.

This is my first post here so hopefully I have made my question clear!


Solution

  • There's no way to detect if a Pre-Roll Video Ad request has been successfully filled until you plan to play it via yourMoviePlayer.playPrerollAdWithCompletionHandler. You could check to see if you receive an error once the UIButton is tapped and request another Pre-Roll Video Ad. I wouldn't suggest this though. The iAd network doesn't like when you send mass amounts of requests and could potentially lower your chance of successfully filling your Pre-Roll Video Ad even more. There's also the problem with never receiving a Pre-Roll Video Ad because the user is located in an unsupported country. Limiting functionality based on the display of an ad is not the best approach due to the unreliable nature of ads being delivered.

        yourMoviePlayer.playPrerollAdWithCompletionHandler { (error) -> Void in
            if (error) != nil {
                NSLog("\(error)")
                // Request another ad
                MPMoviePlayerController.preparePrerollAds()
            }
            else {
                self.yourMoviePlayer.play()
                // Perform desired button action
            }
        }