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)
}
Comments
-
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 almost 4 yearsI get an error from Swift saying, Cannot convert value of type 'AdColonyInterstitial' to expected argument type 'UIViewController'
-
Sami Haddad almost 4 yearsI'm not familiar with the AdColony library, but you need to have a ViewController to be able to show it.
-
Sami Haddad almost 4 yearsCan you try
interstitial.show(withPresenting: vc)
instead ofpresent