1
我想在彈出窗口中顯示iAd。我使用共享實例類來調用displayAd
方法。這裏是我的共享實例類:檢查iAd是否可用
class Share : NSObject ,UIPopoverPresentationControllerDelegate {
static let sharedInstance = Share()
func displayAd(sender:UIViewController) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("PopOverVC") as UIViewController
vc.preferredContentSize = CGSize(width: 310, height: 250)
let navC = UINavigationController(rootViewController: vc)
navC.modalPresentationStyle = UIModalPresentationStyle.Popover
let popOver = navC.popoverPresentationController
popOver?.delegate = self
popOver?.sourceView = sender.view
popOver?.sourceRect = CGRectMake(CGRectGetMidX(sender.view.bounds), CGRectGetMidY(sender.view.bounds),0,0)
popOver?.permittedArrowDirections = UIPopoverArrowDirection(rawValue:0)
navC.navigationBarHidden = true
sender.presentViewController(navC, animated: true) {}
}
}
我使用displayAd
功能顯示酥料餅(包含PopOverVC這是一個IAD) ,然後這是PopOverVC
類:
class PopOverVC: UIViewController,ADBannerViewDelegate {
var ad = ADBannerView()
@IBOutlet var Banner: ADBannerView!
@IBAction func CloseBtn(sender: UIButton) {
self.dismissViewControllerAnimated(true, completion: nil)
}
override func viewDidLoad() {
Banner = ad
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
sharedAd.hidden = false
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
sharedAd.hidden = true
self.dismissViewControllerAnimated(true, completion: nil)
}
}
現在,我想要做的是從其他視圖控制器調用displayAd
方法,然後檢查iAd是否可用,然後顯示它。 現在我的代碼顯示PopOver,然後檢查iAd的可用性,如果不可用,它會關閉。 除非iAd可用,否則我不想顯示PopOver。
無論如何要實現這一目標嗎?
感謝
iAd正在停產:https://developer.apple.com/news/?id=01152016a –