2016-01-10 1 views
1

J'essaie de configurer iAd après avoir cliqué sur le bouton Annuler de JSSAlert. J'ai en fonction JSSAlert que définie alpha pour une vue complète 0,7 .. Et dans le contrôleur de vue je fonction pour iAd et reculer à 1,0 alpha ...IAd interstitiel retardé après avoir appuyé sur le bouton

override func viewDidLoad() { 
     super.viewDidLoad() 
     self.navigationItem.title = "Vyhodnotenie testu" 
     self.showAlert() 

    } 


    func showAlert() { 
     func callback(){} 
     if numberOfPoints > 49 { 
      let customIcon = UIImage(named: "smile") 
      let alertview = JSSAlertView().show(self, title: "Gratulujeme! Uspeli ste.", text: "Dokončili ste test s počtom bodov \(numberOfPoints + 1) z \(maximumNumberOfPoints)!", buttonText: "OK!", color: UIColorFromHex(0x22c411, alpha: 1), iconImage: customIcon) 
      alertview.setTextTheme(.Light) 
      alertview.addAction(myCancelCallback) 
      self.navigationController?.navigationBar.alpha = 0.7 
     } else { 
      let customIcon = UIImage(named: "sad") 
      let alertview = JSSAlertView().show(self, title: "Ľutujeme! Neuspeli ste.", text: "Dokončili ste test s počtom bodov \(numberOfPoints + 1) z \(maximumNumberOfPoints)!", buttonText: "OK!", color: UIColorFromHex(0xd20606, alpha: 1), iconImage: customIcon) 
      alertview.addAction(myCancelCallback) 
      alertview.setTextTheme(.Light) 
      self.navigationController?.navigationBar.alpha = 0.7 
     } 

    } 

    func myCancelCallback() { 
     self.navigationController?.navigationBar.alpha = 1.0 
     self.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Automatic 
    } 


    func interstitialAdWillLoad(interstitialAd: ADInterstitialAd!) { 

    } 

    func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) { 
     interstitialAdView = UIView() 
     interstitialAdView.frame = self.view.bounds 
     view.addSubview(interstitialAdView) 

     interstitialAd.presentInView(interstitialAdView) 
     UIViewController.prepareInterstitialAds() 
    } 

    func interstitialAdActionDidFinish(var interstitialAd: ADInterstitialAd!) { 
     interstitialAd = nil 
     interstitialAdView.removeFromSuperview() 
    } 

    func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool { 
     return true 
    } 

    func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) { 

    } 

    func interstitialAdDidUnload(var interstitialAd: ADInterstitialAd!) { 
     interstitialAd = nil 
     interstitialAdView.removeFromSuperview() 
    } 

Alpha Retour à 1.0 en fonction myCancelCallback travaille mais iAd est retardé .. Qu'est-ce qui peut causer ce retard? Ou comment puis-je y faire face?

Je souhaite afficher iAd immédiatement après avoir appuyé sur OK !.

vidéo comment il fonctionne:

https://www.youtube.com/watch?v=r6LKN-cjaz8&feature=youtu.be

+0

Vous utilisez la méthode ADInterstitialPresentationPolicy.Automatic qui va et demande l'annonce si elle est disponible, puis affichez-le pour que le processus prenne du temps. –

+0

quoi de mieux à utiliser? – patrikbelis

+0

s'il vous plaît vérifier ma réponse, je vous ai donné deux méthodes pour tester cela. –

Répondre

1

Voici ce que tu vas faire, vous devez créer l'interstitiel, y compris le bouton de fermeture par programme, je vous fait un échantillon:

Ajouter une ligne dans info.plist: View controller-based status bar appearance ->NO

dans la méthode AppDelegate didFinishLaunchingWithOptions ajoutez la ligne suivante pour vous assurer que stat nous barre ne sera pas cachée:

UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None) 

Voici un contrôleur de vue de l'échantillon complet de la façon dont votre va ajouter l'interstitiel programme, mais il vous suffit d'écrire l'animation lorsque l'interstitiel montre au lieu d'utiliser addSubview. vous pouvez utiliser la traduction de transformation animée, vous trouverez beaucoup d'exemples à ce sujet.

import UIKit 
import iAd 

class ViewController: UIViewController, ADInterstitialAdDelegate { 


    var interstitialAd:ADInterstitialAd! 
    var interstitialAdView: UIView = UIView() 
    var closeButton:UIButton! 


    override func viewDidLoad() { 
     super.viewDidLoad() 

     NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "loadInterstitialAd", userInfo: nil, repeats: false) 
    } 



    func loadInterstitialAd() { 
     interstitialAd = ADInterstitialAd() 
     interstitialAd.delegate = self 
    } 

    func interstitialAdWillLoad(interstitialAd: ADInterstitialAd!) { 
     print("interstitialAdWillLoad") 
    } 

    func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) { 
     UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Fade) 

     print("interstitialAdDidLoad") 
     UIApplication.sharedApplication().statusBarHidden = true 
     interstitialAdView = UIView() 
     interstitialAdView.frame = self.view.bounds 

     self.navigationController?.navigationBar.addSubview(interstitialAdView) 

     closeButton = UIButton(frame: CGRect(x: 15, y: 15, width: 20, height: 20)) 
     //add a cross shaped graphics into your project to use as close button 
     closeButton.setBackgroundImage(UIImage(named: "close"), forState: UIControlState.Normal) 
     closeButton.addTarget(self, action: Selector("close"), forControlEvents: UIControlEvents.TouchDown) 

     self.navigationController?.navigationBar.addSubview(closeButton) 

     interstitialAd.presentInView(interstitialAdView) 
     UIViewController.prepareInterstitialAds() 
    } 

    func close() { 
     interstitialAdView.removeFromSuperview() 
     closeButton.removeFromSuperview() 
     interstitialAd = nil 
     UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Fade) 


    } 

    func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) { 
     print("interstitialAdActionDidFinish") 
     UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Fade) 
    } 


    func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool { 
     return true 
    } 

    func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) { 
     print("didFailWithError") 
    } 

    func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) { 
     print("interstitialAdDidUnload") 
     close() 
    } 



    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Release any cached data, images, etc that aren't in use. 
    } 

} 

Mise à jour: Il est peut-être il vous suffit d'appeler: UIViewController.prepareInterstitialAds() dans viewDidLoad de votre classe pour télécharger le contenu de l'interstitiel donc chaque fois que vous demandez de le présenter sera prêt et peut-être pas de retard.