0

Im building a test app to show iAd interstitial, which i have to implement it manually to view. well I've done mostly everything but after presenting the iAd interstitial with sometime it closes and gives me : Service session terminated.

Here is my code :

 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()

    }

And another thing that the interstitial should be presented over the status bar even but it shows the status bar while its presented :

Should be like that: https://i.stack.imgur.com/vaTvK.png

But its coming with me like : https://i.stack.imgur.com/f0p2T.png

AaoIi
  • 8,288
  • 6
  • 45
  • 87

1 Answers1

0

Discuss your first issue , I think you have interstitialAd to wrong place. try to set below the viewdidload() method, inshort you need to addsubview to your superview. like this.

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

Discussing your second issue, you need to Manualy hide statusbar while your ADInterstitialAd will present. in InterstitialAd's delegate method. I am not much familiar with SWIFT launguage but as i can understand i think you need to hide Interstitial in this method.

 private func loadInterstitial() {
 //statusbar hide

and you need to again show

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

Note:- Here is the link for hide and show statusbar in SWIFT.

How to hide iOS 7 status bar

Community
  • 1
  • 1
Badal Shah
  • 7,541
  • 2
  • 30
  • 65