0
即時通訊構建測試應用程序以顯示iAd插頁式廣告,我必須手動實施它才能查看。以及我所做的一切大都但有時呈現iAd的間隙後關閉並給我:Service session terminated.
iAd插頁式服務會話終止
這裏是我的代碼:
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()
}
而另一件事是,間隙應在狀態呈現攔均勻,但它顯示在狀態欄,而其提出:
應該是這樣的: http://i.stack.imgur.com/vaTvK.png
但它跟我來想: http://i.stack.imgur.com/f0p2T.png