轻按时无法加载iAd横幅 [英] iAd banner not loading when tapped

查看:66
本文介绍了轻按时无法加载iAd横幅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序底部有一个iAd标语.标语在测试设备上显示正常,并且似乎已正确调用了委托方法.

I have an iAd banner located at the bottom of my app. The banner displays fine on test devices and the delegate methods appear to be called appropriately.

我的问题是.当我点击"您已连接到iAd "横幅时,没有任何内容.通常,我希望会弹出另一个全屏iAd视图.我看到横幅在点击时变暗,然后在松开手指后恢复正常.

My issue is. When I tap the "You're Connected To iAd" banner, nothing is loaded. Normally, I would expect to see a another full screen iAd view pop up. I see the banner darken when I tap it and then it returns to normal when I remove my finger.

bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool)确实会触发,而willLeave是== false.

bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) does fire and willLeave is == false.

class ViewController: UIViewController, UIGestureRecognizerDelegate, ADBannerViewDelegate, GADBannerViewDelegate {
var bannerView: ADBannerView!

override func viewDidLoad() {
    super.viewDidLoad()
    self.bannerView = ADBannerView()
    self.bannerView.frame =  CGRectMake(0, view.frame.height-50, view.frame.width, 50)
    self.bannerView.delegate = self
    self.view.addSubview(bannerView)
    }
}

推荐答案

添加此-ADBannerViewDelegate

创建变量-var adBanner = ADBannerView()

在viewDidLoad()

In viewDidLoad()

        adBanner = iADManager.sharedInstance
        adBanner.delegate = self
        if DeviceType.IS_IPAD {
            adBanner.frame = CGRectMake(0, 20, self.view.frame.width, 65);
        }
        else {
            adBanner.frame = CGRectMake(0, 20, self.view.frame.width, 50);
        }

委托方法 [如果成功提取广告,则会添加子视图,否则将从视图中删除]

func bannerViewDidLoadAd(banner: ADBannerView!) {
        self.view.addSubview(banner)
    }

    func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
        banner.removeFromSuperview()
    }

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
    return true
}

下面是我的shareInstance类.这将有助于内存管理和加载广告.

Below is My shareInstance class. This will more helpful for memory management and loading ads.

class iADManager{

    class var sharedInstance: ADBannerView {
        struct Static {
            static var onceToken: dispatch_once_t = 0
            static var instance: ADBannerView? = nil
        }
        dispatch_once(&Static.onceToken) {
            Static.instance = ADBannerView(adType: ADAdType.Banner)
        }
        return Static.instance!
    }
}

这篇关于轻按时无法加载iAd横幅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆