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

Viewed 674

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 Answers

Try this:

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