Which view controller should I pass in my Swift native code for a Flutter plugin?

邮差的信 提交于 2020-07-03 08:51:26

问题


I am trying to show an Adcolony ad from Swift native code in my Flutter plugin, this is how my swift code looks like -

 if let interstitial = self.interstitial, !interstitial.expired, let 
  rootViewController = UIApplication.shared.keyWindow?.rootViewController
  {
   interstitial.show(withPresenting: rootViewController)
   }

My code works perfectly, but my view controller never displays an interstitial ad. Can anyone help me as I don't know which view controller should I pass to show my ad. The documentation says to use self but my plugin is not a view controller so it doesn't work.


回答1:


Try this:

if let vc = UIApplication.shared.delegate?.window??.rootViewController  as? FlutterViewController {
  interstitial.show(withPresenting: vc)
}            


来源:https://stackoverflow.com/questions/62175368/which-view-controller-should-i-pass-in-my-swift-native-code-for-a-flutter-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!