I'm trying to play a Preroll iAd Video into my game without having a video play afterward which is how I see it's done in all of the examples I've seen. When I go to play the Preroll iAd the AV View Controller is displayed but nothing plays and I get into my error case as shown below saying it couldn't play. What I'm going for is done in games like "Pop The Lock" when it gives you a second chance if you watch a video ad.
In my AppDelegate.swift I have the following code to prepare the iAd video.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
// Override point for customization after application launch.
AVPlayerViewController.preparePrerollAds()
return true
}
Then in my ViewController I have the following to play the ad...
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")
}
})
I wanted to do the same thing and was unsuccessful with pre-roll video. Now I have iAd for my bannerView and i use AdMob for the video advertisement to get a second chance.
Just download AdMob and put in in your app. Then import
create a variable
Then create the func that will load and show the video ad.