Swift: cannot convert value of type 'GameScene

2019-09-14 03:45发布

I am trying to load an admob interstitial ad in my app when the users lost but i can't because i am using spritekit (swift), here's my code:

 self.interstitial.presentFromRootViewController(interstitial)

and here's my error:

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

Hope one of you has the answer! thx

1条回答
Anthone
2楼-- · 2019-09-14 04:04

You're trying to present interstitial from itself.

You should present it from a ViewController which is currently visible:

self.interstitial.presentFromRootViewController(self)

(supposed that self is a View Controller).

Update:

If you follow Google tutorial attentively, you will see there exactly what I'm talking about:

func gameOver() {
  if self.interstitial.isReady {
    self.interstitial.presentFromRootViewController(self)
  }
  // Rest of game over logic goes here.
}
查看更多
登录 后发表回答