对于Flutter插件,我应该在Swift本机代码中传递哪个视图控制器? [英] Which view controller should I pass in my Swift native code for a Flutter plugin?

查看:75
本文介绍了对于Flutter插件,我应该在Swift本机代码中传递哪个视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Flutter插件中显示来自Swift本机代码的Adcolony广告,这就是我的Swift代码的样子-

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)
   }

我的代码运行良好,但视图控制器从不显示插页式广告。有人可以帮助我,因为我不知道应该通过哪个视图控制器来展示广告。该文档说要使用 self ,但是我的插件不是视图控制器,因此无法正常工作。

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.

推荐答案

尝试一下:

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

这篇关于对于Flutter插件,我应该在Swift本机代码中传递哪个视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆