iAd in xcode 6 with Swift

前端 未结 1 1983
栀梦
栀梦 2020-12-01 10:11

I\'m working to implement a banner ad in the scene, but it always reports \"Thread 1: EXC_BREAKPOINT(code=EXC_ARM_BREAKPOINT, subcode=Oxdefe) and the program stops running.

相关标签:
1条回答
  • 2020-12-01 10:25

    This is how I did it, possibly not all of it is necessary.

    I did not use the banner in the Storyboard, so the IBOutlet is not necessary.

    Also, if you manually create a banner, you do not need to set self.canDisplayBannerAds

    This function (ported from ObjC) is how I display the ads.

    func loadAds(){
      adBannerView = ADBannerView(frame: CGRect.zeroRect)
      adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
      adBannerView.delegate = self
      adBannerView.hidden = true
      view.addSubview(adBannerView)
    }
    

    This is called in viewDidLoad. Then, in the didLoadAd delegate method, I set adBannerView.hidden = false and in didFailToReceiveAdWithError, adBannerView.hidden = true

    I think hidden is better than alpha in this situation, as it feels more natural. I believe (but am not sure) that when hidden, the view is not drawn at all by the GPU, while with an alpha of 0, it is still drawn, but made invisible (correct me if I am wrong).

    This is my setup, and it worked for me, so hopefully it will work in your case too!

    0 讨论(0)
提交回复
热议问题