Swift: 无法将类型 'GameScene' 的值转换为预期的参数类型 'UIViewController!'

Swift: cannot convert value of type 'GameScene' to expected argument type 'UIViewController!'

我正在尝试在用户丢失时在我的应用程序中加载 admob 插页式广告,但我不能,因为我使用的是 spritekit (swift),这是我的代码:

 self.interstitial.presentFromRootViewController(interstitial)

这是我的错误:

cannot convert value of type 'GameScene' to expected argument type 'UIViewController!'

希望你们中的一个人有答案!谢谢

您正试图从自身呈现 interstitial

您应该从当前可见的 ViewController 展示它:

self.interstitial.presentFromRootViewController(self)

(假设 self 是一个视图控制器)。

更新:

如果你关注 Google tutorial ,你就会明白我在说什么:

func gameOver() {
  if self.interstitial.isReady {
    self.interstitial.presentFromRootViewController(self)
  }
  // Rest of game over logic goes here.
}