swift - watchOS 退出代码

标签 swift watchkit watchos-3

在 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/

相关文章:

swift - 如果一个tableView位于另一个tableView中,如何同时找到两个tableViewCell的indexPath?

ios - watchOS : How to use HKWorkoutSession without heart rate sensor

ios - 核心数据 - 禁用从缓存加载

Swift Watchkit 让用户在运行应用程序时移动表格中的单元格(行)

ios - 如何查明本地通知的后台操作是否在 iPhone 或 Apple Watch 上得到应答

ios - Swift 中的项目符号列表 - iOS

xcode - 如何在 Swift 中设置 collectionview 单元格之间的间距?

swift - 向 SCNSphere 添加文本

ios - 无需在 Watch 上创建应用程序即可在 Apple Watch Series 3 中读取心率

swift - 在 Swift 3 中使用 downloadTask 没有这样的文件或目录错误