Ios 共享iAd横幅
我正在将我应用程序中的IAD加载到应用程序代理中。它可以正常加载,但是在视图控制器中,它不会显示。 我在应用程序委托中声明广告的代码为Ios 共享iAd横幅,ios,swift,iad,Ios,Swift,Iad,我正在将我应用程序中的IAD加载到应用程序代理中。它可以正常加载,但是在视图控制器中,它不会显示。 我在应用程序委托中声明广告的代码为 var-UIiAd:ADBannerView=ADBannerView() 我在视图控制器中的代码是 class HelpViewController: UIViewController, ADBannerViewDelegate { //MARK: - Properties var UIiAd: ADBannerView = ADBannerV
var-UIiAd:ADBannerView=ADBannerView()
我在视图控制器中的代码是
class HelpViewController: UIViewController, ADBannerViewDelegate {
//MARK: - Properties
var UIiAd: ADBannerView = ADBannerView()
//MARK: - did something
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewWillAppear(animated: Bool) {
//super.viewWillAppear(animated)
let ScreenHeight = UIScreen.mainScreen().bounds.height
UIiAd.delegate = self
UIiAd = self.appDelegate().UIiAd
UIiAd.frame = CGRectMake(0, ScreenHeight - 50, 0, 0)
UIiAd.hidden = true
self.view.addSubview(UIiAd)
}
override func viewWillDisappear(animated: Bool) {
UIiAd.delegate = nil
UIiAd.removeFromSuperview()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//MARK: - iAd
func bannerViewDidLoadAd(banner: ADBannerView!) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(1)
UIiAd.hidden = false
UIView.commitAnimations()
print("Did load ad")
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0)
UIiAd.hidden = true
UIView.commitAnimations()
print("Did fail to receive ad with error \(error)")
}
//MARK: - Functions
func appDelegate() -> AppDelegate {
return UIApplication.sharedApplication().delegate as! AppDelegate
}
}
问题似乎是,BannerViewidLoadad从未被调用。如果横幅加载,我将如何取消隐藏?我实际上已经解决了这个问题。您需要在应用程序委派中执行的操作是
class AppDelegate:UIResponder、UIApplicationDelegate、ADBannerViewDelegate
然后你想制作一个bool,如果加载了广告就会改变
然后您要添加函数func bannerViewDidLoadAd(banner:ADBannerView!){
adLoaded=true
}
这将在加载ad时更改该值
然后在视图控制器中执行以下操作:
override func viewWillAppear(animated: Bool) {
//super.viewWillAppear(animated)
let ScreenHeight = UIScreen.mainScreen().bounds.height
UIiAd.delegate = self
UIiAd = self.appDelegate().UIiAd
UIiAd.frame = CGRectMake(0, ScreenHeight - 50, 0, 0)
canDisplayBannerAds = true
if appDelegate().adLoaded == true {
self.view.addSubview(UIiAd)
}
}
这会将广告添加到您的视图控制器中。如果没有加载广告,则不会加载广告。实际上,我已经修复了此问题。您需要在应用程序委派中执行的操作是
class AppDelegate:UIResponder、UIApplicationDelegate、ADBannerViewDelegate
然后你想制作一个bool,如果加载了广告就会改变
然后您要添加函数func bannerViewDidLoadAd(banner:ADBannerView!){
adLoaded=true
}
这将在加载ad时更改该值
然后在视图控制器中执行以下操作:
override func viewWillAppear(animated: Bool) {
//super.viewWillAppear(animated)
let ScreenHeight = UIScreen.mainScreen().bounds.height
UIiAd.delegate = self
UIiAd = self.appDelegate().UIiAd
UIiAd.frame = CGRectMake(0, ScreenHeight - 50, 0, 0)
canDisplayBannerAds = true
if appDelegate().adLoaded == true {
self.view.addSubview(UIiAd)
}
}
这会将广告添加到您的视图中。如果未加载广告,则控制器不会加载该广告。请参阅以下答案:。您发布的内容不是共享iAd横幅。请参阅以下答案:。你发布的不是共享的iAd横幅。这是错误的
canDisplayBannerAds=true
实际上正在创建一个全新的ADBannerView
,您不应该静态设置.frame
。这是错误的canDisplayBannerAds=true
实际上正在创建一个全新的ADBannerView
,您不应该静态设置.frame
。