Load and Show an MPInterstitialAdController in iOS SpriteKit



I’m having an issue with MoPub in Spritekit that I haven’t had with other apps that are not games. The issue is my view controller is called gameviewcontroller.swift and opening it asks you to login to game center or it welcomes you back from game center, however since adding the interstitial ad it neither brings game center back, nor load the interstitial ad, despite completing the on boarding process of MoPub. Below is the code. Any feedback is helpful.



import UIKit
import SpriteKit
import GameKit
import MoPub

extension SKNode {
class func unarchiveFromFile(file : NSString) -> SKNode? {
if let path = NSBundle.mainBundle().pathForResource(file as String, ofType: “sks”) {
var sceneData = NSData(contentsOfFile: path, options: .DataReadingMappedIfSafe, error: nil)!
var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData)

        archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
        let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameScene
        return scene
    } else {
        return nil


class GameViewController: UIViewController , MPInterstitialAdControllerDelegate {

// TODO: Replace this test id with your personal ad unit id
var interstitial: MPInterstitialAdController =
MPInterstitialAdController(forAdUnitId: "77ce0b65cf81438eb255695afe3b1904")

override func viewDidLoad() {
    self.interstitial.delegate = self
    // Pre-fetch the ad up front

    func interstitialDidLoadAd(interstitial: MPInterstitialAdController) {
        // This sample automatically shows the ad as soon as it's loaded, but
        // you can move this showFromViewController call to a time more
        // appropriate for your app.
        if (interstitial.ready) {

    NSNotificationCenter.defaultCenter().addObserver(self, selector:
        Selector("showAuthenticationViewController"), name:
        PresentAuthenticationViewController, object: nil)

func showAuthenticationViewController() {
    let gameKitHelper = GameKitHelper.sharedInstance
    if let authenticationViewController = gameKitHelper.authenticationViewController {
        presentViewController(authenticationViewController, animated: true,
            completion: nil)

deinit {

override func viewDidLayoutSubviews() {
    if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
        // Configure the view.
        let skView = self.view as! SKView
        skView.showsFPS = false
        skView.showsNodeCount = false
        skView.showsDrawCount = false
        skView.showsPhysics = false

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        skView.ignoresSiblingOrder = false
        /* Set the scale mode to scale to fit the window */
         Adjusted for iOS8 
        scene.scaleMode = .ResizeFill
        scene.size = skView.bounds.size

override func shouldAutorotate() -> Bool {
    return true

override func supportedInterfaceOrientations() -> Int {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)
    } else {
        return Int(UIInterfaceOrientationMask.All.rawValue)

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

override func prefersStatusBarHidden() -> Bool {
    return true



Hi @graphicpeace,

Thanks for reaching out! Could you please reach out to support@mopub.com with device logs from your testing so we can help you look into this?

Thank you!