Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

ios - App approved but no AdMob ads appearing

My iOS application was denied due to Apple not finding my ads during the review process. I uploaded my application again, included directions on how to see the ads, and it was approved today. Now, once my friends and family downloaded the application no ads are showing up. I checked my AdMob account and no impressions showed up so I don't know what's wrong. Has anyone had this happened to them? Also, it hasn't been 24hrs yet since the app was approved. Since Apple approved it I assume that they have seen the ads. My application shows ads when you start using the filters after you pick a photo. AdMob shows 61 impressions, 61 requests, and 100% fill rate.

// Initialize Apple iAd banner
func initiAdBanner() {
    iAdBannerView = ADBannerView(frame: CGRectMake(0, self.view.frame.size.height, 0, 0) )
    iAdBannerView.delegate = self
    iAdBannerView.hidden = true
    view.addSubview(iAdBannerView)
}

// Initialize Google AdMob banner
func initAdMobBanner() {
    if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad {
        // iPad banner
        adMobBannerView.adSize =  GADAdSizeFromCGSize(CGSizeMake(728, 90))
        adMobBannerView.frame = CGRectMake(0, self.view.frame.size.height, 728, 90) 
    } else {
        // iPhone banner
        adMobBannerView.adSize =  GADAdSizeFromCGSize(CGSizeMake(320, 50))
        adMobBannerView.frame = CGRectMake(0, self.view.frame.size.height, 320, 50)
    }
    adMobBannerView.adUnitID = "AdMobPublisherID"
    adMobBannerView.rootViewController = self
    adMobBannerView.delegate = self
    // adMobBannerView.hidden = true
    view.addSubview(adMobBannerView)
    var request = GADRequest()
    adMobBannerView.loadRequest(request)
}

// Hide the banner
func hideBanner(banner: UIView) {
    if banner.hidden == false {
        UIView.beginAnimations("hideBanner", context: nil)
        // Hide the banner moving it below the bottom of the screen
        banner.frame = CGRectMake(0, self.view.frame.size.height, banner.frame.size.width, banner.frame.size.height)
        UIView.commitAnimations()
        banner.hidden = true
    }
}

// Show the banner
func showBanner(banner: UIView) {
    if banner.hidden == true {
        UIView.beginAnimations("showBanner", context: nil)
        // Move the banner on the bottom of the screen
        banner.frame = CGRectMake(0, (self.view.frame.size.height-70) - banner.frame.size.height,
        banner.frame.size.width, banner.frame.size.height);
        UIView.commitAnimations()
        banner.hidden = false
    }
}

// iAd banner available
func bannerViewWillLoadAd(banner: ADBannerView!) {
    println("iAd loaded!")
    hideBanner(adMobBannerView)
    showBanner(iAdBannerView)
}

// NO iAd banner available
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    println("iAd can't looad ads right now, they'll be available later")
    hideBanner(iAdBannerView)
    var request = GADRequest()
    adMobBannerView.loadRequest(request)
}

// AdMob banner available
func adViewDidReceiveAd(view: GADBannerView!) {
    println("AdMob loaded!")
    hideBanner(iAdBannerView)
    showBanner(adMobBannerView)
}

// NO AdMob banner available
func adView(view: GADBannerView!, didFailToReceiveAdWithError error:    GADRequestError!) {
    println("AdMob Can't load ads right now, they'll be available later 
(error)")
    hideBanner(adMobBannerView)
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ads are now appearing in your application. When your application is approved by Apple it still must be approved by the iAd team to receive iAd advertisements. This can take a few additional days. As a result, neither of your advertisements were being shown in your application. You can test this by going to Settings>Developer>and setting your fill rate to 0% on your development device. The reason neither ad is being shown if iAd fails to load initially is because of this function:

    // Show the banner
    func showBanner(banner: UIView) {
        if banner.hidden == true {
            UIView.beginAnimations("showBanner", context: nil)

            // Move the banner on the bottom of the screen
            banner.frame = CGRectMake(0, (self.view.frame.size.height-70) - banner.frame.size.height,
                banner.frame.size.width, banner.frame.size.height);

            UIView.commitAnimations()
            banner.hidden = false
        }
    }

You're checking for if banner.hidden == true but your adMobBannerView's hidden value is never set to true until an iAd banner is loaded. Seeing as no iAd banner was being loaded prior to the approval by iAd's team this condition was never being met. This condition will also never be met in countries that do not support iAd or if iAd fails to load an ad initially.

Also, there's alot of jumping around when your ads load due to you animating them on and off the screen. A more elegant approach would be to animate their alpha values so the user does not notice when your ads change. You can also eliminate alot of your code. I've rewritten what you're trying to accomplish and commented out the reasoning behind it.

import UIKit
import iAd

class ViewController: UIViewController, ADBannerViewDelegate, GADBannerViewDelegate {

var iAdBannerView : ADBannerView = ADBannerView()
var adMobBannerView : GADBannerView = GADBannerView()

override func viewDidLoad() {
    super.viewDidLoad()
    loadAds()
}

func loadAds() {
    // iAd
    // Changed banners width to match the width of the view it is on
    // You need to set the y origin relative to your view. Not a static number.
    iAdBannerView = ADBannerView(frame: CGRectMake(0, self.view.frame.size.height - iAdBannerView.frame.height, self.view.frame.size.width, iAdBannerView.frame.height))
    iAdBannerView.delegate = self
    view.addSubview(iAdBannerView)
    // Hide iAd initially
    iAdBannerView.alpha = 0.0

    // AdMob
    // Changed adSize to Googles set banner size
    adMobBannerView.adSize = kGADAdSizeBanner
    // Changed banners width to match the width of the view it is on
    // You need to set the y origin relative to your view. Not a static number.
    adMobBannerView.frame = CGRectMake(0, self.view.frame.size.height - adMobBannerView.frame.height , self.view.frame.size.width, adMobBannerView.frame.height)
    adMobBannerView.rootViewController = self
    adMobBannerView.delegate = self
    adMobBannerView.adUnitID = "AdMobPublisherID"
    // Dont need var request = GADRequest()
    adMobBannerView.loadRequest(GADRequest())
    // Do not hide AdMob initially
    view.addSubview(adMobBannerView)
}

// Use bannerViewDidLoadAd function so we know ad is fully loaded
func bannerViewDidLoadAd(banner: ADBannerView!) {
    println("iAd has an ad to show")
    // Animate fade of banners
    UIView.beginAnimations(nil, context: nil)
    // Show iAd
    iAdBannerView.alpha = 1.0
    // Hide AdMob
    adMobBannerView.alpha = 0.0
    UIView.commitAnimations()
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    println("iAd failed to load an ad because (error)")
    // Animate fade of banners
    UIView.beginAnimations(nil, context: nil)
    // Hide iAd
    iAdBannerView.alpha = 0.0
    // Show AdMob
    adMobBannerView.alpha = 1.0
    UIView.commitAnimations()
}

This favors iAd and falls back to AdMob if iAd fails to load an ad. You don't need to check for when AdMob fails to load an ad as its fill rate is almost always 100%, and if there's no AdMob ad I doubt there's an iAd ad to show.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...