美文网首页
SwiftUI 监听APP生命周期

SwiftUI 监听APP生命周期

作者: 我是卖报的小行家 | 来源:发表于2023-07-19 08:47 被阅读0次

    在做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("......")
                        }
                    }
    

    相关文章

      网友评论

          本文标题:SwiftUI 监听APP生命周期

          本文链接:https://www.haomeiwen.com/subject/kumqudtx.html