在 Xcode 中,有一个地方可以设置界面 Controller 关闭时的 Action :
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
但是,我的 watchOS 应用程序需要在应用程序完全退出时执行操作,即主屏幕可见。不是当 watch 被简单地放下并且屏幕变暗时,因为该应用程序仍在作为锻炼应用程序运行并且正在执行操作。
有办法吗?
最佳答案
在 ExtensionDelegate
中,您会找到 applicationWillResignActive
方法。
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, etc.
您可以使用此方法来完成您需要的操作。
关于swift - watchOS 退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42676247/