2015-09-25 101 views
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

回答

0

討論您的第一個問題, 我認爲您有interstitialAd錯誤的地方。嘗試設置下面的viewdidload()方法,inshort你需要添加到你的超級視圖。喜歡這個。

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

討論 需要Manualy隱藏狀態欄,而你的ADInterstitialAd將展示你的第二個問題。在InterstitialAd的委託方法中。 我對SWIFT語言不太瞭解,但據我所知,我認爲您需要在此方法中隱藏插頁式廣告。

private func loadInterstitial() { 
//statusbar hide 

,你需要再次顯示

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

注: - 這裏是鏈接在SWIFT隱藏和顯示狀態欄。

How to hide iOS 7 status bar