点击时 iAd 横幅未加载

iAd banner not loading when tapped

我的应用程序底部有一个 iAd 横幅。横幅在测试设备上显示良好,委托方法似乎被正确调用。

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

bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) 会触发,willLeave == 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()中

        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 class。这将更有利于内存管理和加载广告。

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!
    }
}

问题是我实现了...

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {NSLog("Banner Leaving... \(willLeave)")
    return willLeave
}

willLeave 设置为 false 所以我要么必须 return true 要么不实施该方法。我选择 return true