iosswiftadsrootviewheyzap

Heyzap Ad Mediation, only work for rootviewcontroller


I started using Heyzap today to integrate multiple ad networks in my iOS project. The integration went well as shown in the image below.

However, I run into problems while trying to show ads. I get warning messages saying that the ads are getting presented on top of rootviewcontroller and it's not in the view hierarchy right now.

*Warning: Attempt to present <GADInterstitialViewController:    0x14f63d9c0> on <TwentyFour.GameEntranceViewController: 0x14f5094c0> whose view is not in the window hierarchy!*

"GameEntranceViewController is my RootViewController"

How can I present ads if it's not for the rootViewController? I have my code below, what did I do wrong?

  1. In AppDelegate

    HeyzapAds.startWithPublisherID("publisher_id")
    HZInterstitialAd.fetch()
    
  2. In viewDidLoad or viewDidAppear in a view controller which is not RootViewController.

    if HZInterstitialAd.isAvailable() {
    
      HZInterstitialAd.show()
    
    }
    

Thanks a lot!!! Mediation Test Suite shown, with multiple networks integrated correctly


Solution

  • I'm an iOS engineer at Heyzap. You can create an HZShowOptions object, set the viewController property on it, and pass that to showWithOptions:

    let options:HZShowOptions = HZShowOptions()
    options.viewController = self
    HZInterstitialAd.showWithOptions(options)