如何在 swift 4 中访问应用程序委托中的视图控制器功能

how to access view controller functions in the app delegate in swift 4

Xcode gives me the error "Instance member 'pauseGame322' cannot be used on type 'ViewController'; did you mean to use a value of this type instead?"

func applicationWillTerminate(_ application: UIApplication) {
    // Called when the application is about to terminate. Save data if  appropriate. See also applicationDidEnterBackground:.
    ViewController.pauseGame322(ViewController)
}

尝试在您的视图控制器中添加观察者

NotificationCenter.default.addObserver(self,
selector: #selector(applicationWillTerminate),
name: .UIApplicationWillTerminate,
object: nil)

回调

@objc func applicationWillTerminate() {

     self.pauseGame322()

}