我正在构建一个测试应用来展示iAd插页式广告,我必须手动实现它才能查看。好吧,我已经完成了大部分工作,但是在展示了iAd插页式广告后,它会关闭并给我:Service session terminated.
这是我的代码:
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()
}
另一件事是,插页式广告应该在状态栏上显示,但它会显示状态栏:
答案 0 :(得分:0)
讨论你的第一期,
我认为你有interstitialAd
错误的地方。尝试在viewdidload()
方法下方设置,您需要将superubview添加到您的超级视图中。像这样。
override func viewDidLoad()
{
super.viewDidLoad()
super.view.addSubview(interAdView)
//write other stuff
讨论你的第二个问题,
您需要在ADInterstitialAd
出现时手动隐藏状态栏。在InterstitialAd
的委托方法中。
我对SWIFT语言并不熟悉,但据我所知,我认为你需要在这种方法中隐藏非页内广告。
private func loadInterstitial() {
//statusbar hide
你需要再次展示
func interstitialDidDismissScreen (interstitial: GADInterstitial) {
//show statusbar
注意: - 这是SWIFT中隐藏和显示状态栏的链接。