测试iAd无法加载 [英] Test iAds won't load
问题描述
几天来,我一直在挠头.我无法在模拟器(或真实的硬件)中显示iAd.
I've been scratching my head about this for a couple of days. I can't get iAds to show up in the simulator (or real hardware).
- 我在iTunes Connect上填写了所有合同信息
- 为该应用创建了开发配置文件
- 链接iAd框架并将其导入到ViewController的swift文件顶部
- 将ViewController设为ADBannerViewDelegate的子类
- 为委托人实现了3种方法(见下文)
我不知道为什么没有加载测试广告.还有其他人有这个问题吗?据我了解,您不再需要通过iTunes Connect为iAds分别注册每个应用程序.
I can't figure out why the test ads aren't loading. Has anybody else had this problem? As I understand it you no longer have to register each app individually for iAds through iTunes Connect anymore.
尽管我怀疑问题出在安装程序中,但我还是在下面提供了我的代码以供参考.
I'll include my code below for reference, though I have a suspicion that the problem is somewhere in the setup.
import UIKit
import iAd
class AdViewController: UIViewController, ADBannerViewDelegate {
var bannerView = ADBannerView()
override func viewDidLoad() {
super.viewDidLoad()
self.canDisplayBannerAds = true
bannerView.frame = CGRectMake(0, self.view.frame.height-50, self.view.frame.width, 50)
view.addSubview(bannerView)
bannerView.delegate = self
bannerView.hidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
self.bannerView.hidden = false
println("bannerView unhidden")
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
bannerView.hidden = true
println("bannerView hidden")
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return willLeave
}
}
今天早上,我尝试从gitHub下载并运行一些iAd演示,以查看是否可以使它们正常工作,但无济于事.我认为代码是正确的,因此在其他地方一定有问题. https://github.com/sarchak/iAds
This morning I tried downloading and running some iAd demos from gitHub just to see if I could get them to work, but to no avail. I assume the code is correct, so something must be wrong elsewhere. https://github.com/sarchak/iAds
推荐答案
不建议手动设置广告视图的大小.
使用init()
方法,然后调整框架没有任何意义
it is not recommend to manually set the size of an ad view.
use init()
method and then adjust the frame doesn't make any sense
您应该像这样初始化横幅视图:
let bannerView = ADBannerView(adType:ADAdType.Banner)
然后立即设置其委托并将其添加到根视图
you should initialize your banner view like this:
let bannerView = ADBannerView(adType:ADAdType.Banner)
and then immediately set its delegate and add it to the root view
这篇关于测试iAd无法加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!