简体   繁体   English

iAd非页内广告服务会话已终止

[英]iAd interstitial Service session terminated

Im building a test app to show iAd interstitial, which i have to implement it manually to view. 我正在构建一个测试应用程序以显示iAd插页式广告,我必须手动实施它才能查看。 well I've done mostly everything but after presenting the iAd interstitial with sometime it closes and gives me : Service session terminated. 好吧,我几乎做了所有事情,但是在展示iAd插页式广告有时会关闭并提示我: Service session terminated.

Here is my code : 这是我的代码:

 var interAd = ADInterstitialAd()
    var interAdView: UIView = UIView()

    var closeButton = UIButton(type: UIButtonType.System) as UIButton

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        closeButton.frame = CGRectMake(10, 13, 20, 20)
        closeButton.layer.cornerRadius = closeButton.frame.size.width / 2
        closeButton.clipsToBounds = true
        closeButton.setTitle("x", forState: .Normal)
        closeButton.contentVerticalAlignment = UIControlContentVerticalAlignment.Top
        closeButton.setTitleColor(UIColor(red: 109/255, green: 109/255, blue: 109/255, alpha: 1), forState: .Normal)
        closeButton.backgroundColor = UIColor.whiteColor()
        closeButton.layer.borderColor = UIColor(red: 109/255, green: 109/255, blue: 109/255, alpha: 1).CGColor
        closeButton.layer.borderWidth = 2
        closeButton.addTarget(self, action: "close:", forControlEvents: UIControlEvents.TouchDown)


    }

    func close(sender: UIButton) {
        closeButton.removeFromSuperview()
        interAdView.removeFromSuperview()
    }

    @IBAction func showAd(sender: UIButton) {
        loadAd()
    }

    func loadAd() {
        print("load ad")
        interAd = ADInterstitialAd()
        interAd.delegate = self
    }

    func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
        print("ad did load")

        interAdView = UIView()
        interAdView.frame = self.view.bounds
        super.view.addSubview(interAdView)

        interAdView.layer.transform = CATransform3DMakeTranslation(0, 500, 0)
        UIView.animateWithDuration(0.4, animations: {
            self.interAdView.layer.transform = CATransform3DMakeTranslation(0,0,0)
            self.interAd.presentInView(self.interAdView)
            UIViewController.prepareInterstitialAds()
            self.interAdView.addSubview(self.closeButton)

        })

    }

    func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {

    }

    func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
        print("failed to receive")
        print(error.localizedDescription)

        closeButton.removeFromSuperview()
        interAdView.removeFromSuperview()

    }

And another thing that the interstitial should be presented over the status bar even but it shows the status bar while its presented : 另外,插页式广告也应显示在状态栏上,但在显示状态栏时会显示状态栏:

Should be like that: http://i.stack.imgur.com/vaTvK.png 应该是这样的: http : //i.stack.imgur.com/vaTvK.png

But its coming with me like : http://i.stack.imgur.com/f0p2T.png 但它像我一样出现: http : //i.stack.imgur.com/f0p2T.png

Discuss your first issue , I think you have interstitialAd to wrong place. 讨论您的第一个问题,我认为您把interstitialAd放错了地方。 try to set below the viewdidload() method, inshort you need to addsubview to your superview. 尝试在viewdidload()方法下面进行设置,简而言之,您需要将subview添加到您的超级视图中。 like this. 像这样。

override func viewDidLoad() 
{
super.viewDidLoad()
super.view.addSubview(interAdView)
 //write other stuff

Discussing your second issue, you need to Manualy hide statusbar while your ADInterstitialAd will present. 讨论你的第二个问题,你需要Manualy隐藏状态栏,而你的ADInterstitialAd将呈现。 in InterstitialAd 's delegate method. InterstitialAd的委托方法中。 I am not much familiar with SWIFT launguage but as i can understand i think you need to hide Interstitial in this method. 我对SWIFT的使用语言不是很熟悉,但是据我了解,我认为您需要使用此方法隐藏非页内广告。

 private func loadInterstitial() {
 //statusbar hide

and you need to again show 然后您需要再次显示

  func interstitialDidDismissScreen (interstitial: GADInterstitial) {
   //show statusbar

Note:- Here is the link for hide and show statusbar in SWIFT. 注意:-这是SWIFT中隐藏和显示状态栏的链接。

How to hide iOS 7 status bar 如何隐藏iOS 7状态栏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM