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

411

Try this:

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

Arnav

Flutter developer

Updated on December 21, 2022

Comments

  • Arnav
    Arnav over 1 year

    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.

  • Arnav
    Arnav almost 4 years
    I get an error from Swift saying, Cannot convert value of type 'AdColonyInterstitial' to expected argument type 'UIViewController'
  • Sami Haddad
    Sami Haddad almost 4 years
    I'm not familiar with the AdColony library, but you need to have a ViewController to be able to show it.
  • Sami Haddad
    Sami Haddad almost 4 years
    Can you try interstitial.show(withPresenting: vc) instead of present