在做Apple Watch开发时候,有用到监听APP处于后台以及进入前台的状态,按照以下代码处理即可
@Environment(\.presentationMode) var presentationMode
Text("hello")
.onChange(of: scenePhase) { newValue in
switch newValue {
case .background:
print("程序进后台了")
saveStartTime()
case .active:
print("程序激活了")
case .inactive:
print("程序挂起来了。。。")
fetchStartTime()
default:
print("......")
}
}
网友评论