2016-01-14 3 views
3

J'essaie de jouer une Preroll iAd Video dans mon jeu sans avoir à jouer de la vidéo par la suite, comme je le vois dans tous les exemples que j'ai vus. Quand je vais jouer au Preroll iAd, le contrôleur AV View est affiché, mais rien ne joue et j'entre dans mon cas d'erreur comme indiqué ci-dessous, disant qu'il ne peut pas jouer. Ce que je vais faire est fait dans des jeux comme "Pop The Lock" quand il vous donne une seconde chance si vous regardez une publicité vidéo.Comment implémentez-vous iAd Preroll Video dans Swift et iOS 9?

Dans mon AppDelegate.swift j'ai le code suivant pour préparer la vidéo iAd.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 
{ 

     // Override point for customization after application launch. 
     AVPlayerViewController.preparePrerollAds() 
     return true 
} 

Puis dans mon ViewController je donne les résultats suivants pour jouer l'annonce ...

import AVFoundation 
import iAd 

//this is declared at the top 
let adPlayerController = AVPlayerViewController() 

//this gets called inside of a function 
adPlayerController.playPrerollAdWithCompletionHandler({ (error) -> Void in 

      if error != nil 
      { 
       print(error) 
       print("Ad could not be loaded") 
      } 
      else 
      { 
       print("Ad loaded") 
      } 
     }) 
+0

double possible de [Intégrer iAd intégration vidéo pré-roll dans mon application?] (Http://stackoverflow.com/a/32182076/2108547) –

+0

double possible de [Intégrer l'intégration vidéo pré-roll iAd en mon application?] (http://stackoverflow.com/questions/32173294/integrate-iad-pre-roll-video-integration-in-my-app) – rene

Répondre

0

que je voulais faire la même chose et a échoué avec vidéo pré-roll. Maintenant, j'ai iAd pour mon bannerView et j'utilise AdMob pour la publicité vidéo pour avoir une seconde chance.

Téléchargez simplement AdMob et insérez-le dans votre application. Puis importer

import GoogleMobileAds 

créer une variable

var interstitial: GADInterstitial! 

Ensuite, créez la func qui va charger et afficher l'annonce vidéo.

func loadAd() { 

    self.interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910") 
    let request = GADRequest() 
    // Requests test ads on test devices. 
    request.testDevices = ["e23db0f2cf8d82b7b4f23ede7df2f928"] 
    interstitial.delegate = self 
    self.interstitial.loadRequest(request) 
} 

func showAd() { 
    if self.interstitial.isReady { 
     let vc = self.view!.window?.rootViewController 

     self.interstitial.presentFromRootViewController(vc) 
    } 
} 


func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) { 
    print("Video Ad did not load") 

} 

func interstitialDidDismissScreen(ad: GADInterstitial!) { 

} 

func interstitialDidReceiveAd(ad: GADInterstitial!) { 

} 

func interstitialWillLeaveApplication(ad: GADInterstitial!) { 

} 

func interstitialWillPresentScreen(ad: GADInterstitial!) { 

} 

func interstitialWillDismissScreen(ad: GADInterstitial!) { 

}