ios - 我应该为 Flutter 插件传入我的 Swift native 代码中的哪个 View Controller ?

标签 ios swift flutter dart plugins

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

 if let interstitial = self.interstitial, !interstitial.expired, let 
  rootViewController = UIApplication.shared.keyWindow?.rootViewController
  {
   interstitial.show(withPresenting: rootViewController)
   }

我的代码运行完美,但我的 View Controller 从不显示插页式广告。任何人都可以帮助我,因为我不知道应该传递哪个 View Controller 来显示我的广告。文档说要使用 self 但我的插件不是 View Controller 所以它不起作用。

最佳答案

试试这个:

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

关于ios - 我应该为 Flutter 插件传入我的 Swift native 代码中的哪个 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62175368/

相关文章:

objective-c - 从 xcode 中删除 "Format String is not a string literal"警告

ios - 使用 AFNetworking 从 AVCapture 上传文件

ios - 无法将专辑封面设置为背景颜色

flutter - 如何在Flutter中实现用户消息窗口?

flutter - 如何获得Dart运行时的代码覆盖率?

text - 如何在 Flutter 中创建响应式文本小部件?

ios - 如何在不单击通知 ios 的情况下在接收本地通知时自动启动应用程序

ios - 从不兼容的 double 类型分配给 NSNumber

ios - Bixolon 自动连接 Mfi iOS

ios - 如何检测 PKAddPassesViewController 中的添加按钮按下