轻按时无法加载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!
}
}