Swift Helper类ViewController

时间:2016-02-17 11:48:17

标签: swift viewcontroller ads

我已经为我的spritekit游戏设计了一个iAds和AdMob助手,可以在gitHub上找到。

https://github.com/crashoverride777/Swift2-iAds-AdMob-CustomAds-Helper

帮助程序的设计方式是设置presentViewController属性

Ads.sharedInstance.presentingViewController = self

一旦你的游戏在你的gameViewController中启动(游戏通常只有1个viewControlle,所以它工作正常)。

但有些用户报告说,在常规UIKit应用中使用帮助程序时,更改视图控制器时广告无法正确显示。

对于UiKit,广告助手略有改变,辅助方法现在看起来像这样

func showBannerAd(viewController: UIViewController) {
        self.presentingViewController = viewController
       ....
}

并且您可以在ViewControllers中调用它们

Ads.sharedInstance.showBannerAd(self)

但是,更改ViewControllers时仍会出现问题。我相信它与rootViewController有关。

有人可以解释我如何在UIKitApps中使用这个帮助器,主要是如何使用具有viewControllerProperty的帮助器

 presentingViewController: UIViewController

但确保此属性始终是rooViewController,因此无论在UIKit应用程序中使用哪个ViewController,Ads都会显示。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我认为问题在于我在展示广告时没有调用rootViewController。

现在我这样称呼它

presentingViewController.view?.window?.rootViewController?.presentView...

应确保即使使用多个视图控制器也始终显示广告。