按下按钮后,插页式iAd延迟

时间:2016-01-10 11:08:21

标签: swift delay iad interstitial

我在点击JSSAlert上的取消按钮后尝试设置iAd。我在JSSAlert函数中为全视图设置了alpha 0.7 ..在视图控制器中我有iAd功能并将alpha设置为1.0 ......

sizePolicy

功能 myCancelCallback 中的Alpha返回1.0正在运行,但iAd被延迟..什么可能导致延迟?或者我该如何处理它?<​​/ p>

我想在按OK后立即显示iAd!

视频如何运作:

https://www.youtube.com/watch?v=r6LKN-cjaz8&feature=youtu.be

1 个答案:

答案 0 :(得分:1)

<强>更新

  

iAd App Network Shutdown截至2016年12月31日,iAd App Network   不再被提供。如果您想推广自己的应用,可以   使用搜索广告,Apple新闻或第三方网络进行广告宣传   广告卖家。

     

参考:https://developer.apple.com/support/iad/

以下是您要做的事情,您必须以编程方式创建包含关闭按钮的插页式广告,我刚刚为您制作了示例:

在info.plist中添加行:View controller-based status bar appearance - &gt; NO

在AppDelegate中的

didFinishLaunchingWithOptions方法添加以下行以确保状态栏不会被隐藏:

UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)

以下是一个完整的示例视图控制器,用于以编程方式添加插页式广告,但您只需在显示插页式广告时编写动画,而不是仅使用addSubView。你可以使用动画变换翻译,你会发现很多关于它的样本。

import UIKit
import iAd

class ViewController: UIViewController, ADInterstitialAdDelegate {


    var interstitialAd:ADInterstitialAd!
    var interstitialAdView: UIView = UIView()
    var closeButton:UIButton!


    override func viewDidLoad() {
        super.viewDidLoad()

        NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "loadInterstitialAd", userInfo: nil, repeats: false)
    }



    func loadInterstitialAd() {
        interstitialAd = ADInterstitialAd()
        interstitialAd.delegate = self
    }

    func interstitialAdWillLoad(interstitialAd: ADInterstitialAd!) {
        print("interstitialAdWillLoad")
    }

    func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
        UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Fade)

        print("interstitialAdDidLoad")
        UIApplication.sharedApplication().statusBarHidden = true
        interstitialAdView = UIView()
        interstitialAdView.frame = self.view.bounds

        self.navigationController?.navigationBar.addSubview(interstitialAdView)

        closeButton = UIButton(frame: CGRect(x: 15, y:  15, width: 20, height: 20))
        //add a cross shaped graphics into your project to use as close button
        closeButton.setBackgroundImage(UIImage(named: "close"), forState: UIControlState.Normal)
        closeButton.addTarget(self, action: Selector("close"), forControlEvents: UIControlEvents.TouchDown)

        self.navigationController?.navigationBar.addSubview(closeButton)

        interstitialAd.presentInView(interstitialAdView)
        UIViewController.prepareInterstitialAds()
    }

    func close() {
        interstitialAdView.removeFromSuperview()
        closeButton.removeFromSuperview()
        interstitialAd = nil
        UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Fade)


    }

    func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {
        print("interstitialAdActionDidFinish")
        UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Fade)
    }


    func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool {
        return true
    }

    func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
        print("didFailWithError")
    }

    func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
        print("interstitialAdDidUnload")
        close()
    }



    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Release any cached data, images, etc that aren't in use.
    }

}

更新:您可能需要在班级的UIViewController.prepareInterstitialAds()致电viewDidLoad来下载插页式广告的内容,以便每当您要求提交插页式广告时准备好,然后可能没有延迟。