Although the iAd Pre-Roll Video Ad plays successfully, I am receiving an error in the Pre-Roll Video Ad. I am wondering if there is an error in my code.
This is the error message:
iAdPreRollVideoAdTest[ ... : ... ] nil
This is the code that prints the error:
moviePlayer.playPrerollAdWithCompletionHandler { (error) -> Void in
NSLog("\(error)")
self.moviePlayer.view.removeFromSuperview()
//I want to remove it after the ad plays
}
Is there something wrong with my code? Or is this normal?
No, there is nothing wrong with your code, but there's no sense in printing error
to the console if its value is equal to nil
.
nil
is essentially the absence of a valid value. So, the reason nil
is being printed to your console is because error
contains no value. We only want error
printed to the console in cases where there is actually an error to print. The way we accomplish this is by checking if error
is not equal, !=
, to nil
, and if it is not, we print the error to the console. For example:
moviePlayer.playPrerollAdWithCompletionHandler { (error) -> Void in
if (error) != nil {
println("\(error)")
}
self.moviePlayer.view.removeFromSuperview()
}