问题
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