【发布时间】:2020-02-12 07:55:24
【问题描述】:
我来自 react-native,是 Swift 和 SwiftUI 的初学者,我很好奇当应用返回前台时如何在特定屏幕上执行操作和更新状态。我想检查通知的状态(“允许”、“拒绝”等)并更新 UI。
这是一些示例代码 - 这是我要更新的视图:
struct Test: View {
@State var isNotificationsEnabled : Bool
var body : some View {
Toggle(isOn: self.isNotificationsEnabled) {
Text("Notifications")
}
}
}
到目前为止,我一直在阅读的是,您需要在 SceneDelegate.swift 中编辑 func sceneWillEnterForeground(_ scene: UIScene),但是我到底如何从那里更新我的 Test 结构的状态?我认为我们需要某种全局状态,但这只是猜测。
有什么建议吗?
【问题讨论】: