IAd Interstitial Ads Not Displaying Sequentially? And not at all on a simulator
iAd interstitials are not showing at all on the iPhone simulator, nor are they showing consistently on my iPhone. I went to developer settings, changed the fill factor to 100%, and turned on Unlimited ad. No difference ... the interstitial will usually show the first time it was supposed to and then won't show again anywhere from a few minutes to fifteen minutes. Don't know what is causing the time difference.
Also, there seems to be no way to track if there will be an interstitial show or not / if it actually showed or didn't. I understand there is an interstitial delegate, but it doesn't seem to be used anymore. The way I call my interstitial usage is usingviewController.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Automatic
Thank!
source to share
So it seems like the use requestInterstitialAdPresentation
is only meant to be used when yours is ADInterstitialPresentationPolicy
set to Automatic
. When embedding your interstitial ads with using, Manual
ADInterstitialPresentationPolicy
you must usepresentInView
for announcing ads at their own intervals. When presenting your interstitial content in this way, it doesn't load with its own close button to dismiss itself. So what I did was created a <T26> to represent the interstitial in and used the interstitial delegate methods to reject the <T26>. A mismatch when receiving an ad from the iAd network still occurs in testing. Sometimes you get an ad, sometimes it won't load, which allows us to request a new ad, and sometimes nothing happens at all. This is similar to the nature of the iAd internodes.
import UIKit
import iAd // Import iAd
class ViewController: UIViewController, ADInterstitialAdDelegate { // Include the delegate
var iAdInterstitial = ADInterstitialAd() // Our ad
var iAdInterstitialView = UIView() // View to present our ad in
var adLoaded = false // Bool to keep track if an ad is loaded or not
override func viewDidLoad() {
super.viewDidLoad()
setupAd()
}
func setupAd() {
// Set presentation to manual so we can choose when to present the interstitial
// Setting this will also fetch an interstitial ad for us
self.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Manual
iAdInterstitial.delegate = self // Set the delegate
// Make our view the same size as the view we will be presenting in
iAdInterstitialView.frame = self.view.bounds
}
func requestNewAd() {
// This will fetch an ad for us
ViewController.prepareInterstitialAds()
println("Requesting new ad")
}
@IBAction func presentAdButton(sender: AnyObject) {
if (adLoaded) {
// We have an ad that is loaded so lets present it
self.view.addSubview(iAdInterstitialView)
iAdInterstitial.presentInView(iAdInterstitialView)
}
else {
// No ad has been loaded
println("Ad not loaded")
}
}
func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
// Kinda works as expected
// Sometimes is called prematurely
// Sometimes takes minutes after ad is dismissed to be called
println("interstitialAdDidUnload")
// Get new ad
adLoaded = false
iAdInterstitialView.removeFromSuperview()
requestNewAd()
}
func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
// Failed to load ad so lets try again
println("didFailWithError: \(error)")
requestNewAd()
}
func interstitialAdWillLoad(interstitialAd: ADInterstitialAd!) {
// There is an ad and it has begun to download
println("interstitialAdWillLoad")
}
func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
// We got an ad
println("interstitialAdDidLoad")
adLoaded = true
}
func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool {
println("interstitialAdActionShouldBegin")
return true;
}
func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {
// Done with this ad. Lets get a new one
println("interstitialAdActionDidFinish")
iAdInterstitialView.removeFromSuperview()
adLoaded = false
requestNewAd()
}
source to share