【发布时间】:2020-11-05 12:28:27
【问题描述】:
如果位置服务关闭或被拒绝,我会弹出一个警报,将用户引导至“设置”,以便可以打开位置服务。它通过将状态变量 showAlert 设置为 true 来显示。我的代码是:
Alert(title: Text("Location Services"),
message: Text("Location Services is off or denied. The app must have your location to function. Please enable Location Services for the app in Settings."),
primaryButton: .default(Text("Settings"), action: {
self.showAlert = false // my attempt to clear the alert
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
}),
secondaryButton: .default(Text("Okay")))
我遇到的问题是,当用户单击设置按钮转到设置以打开定位服务时,警报不会消失。因此,当用户启用后返回应用程序时 他们,警报仍然存在,说明服务未开启。这是一种糟糕的用户体验,我希望在用户返回之前将其关闭。从代码中可以看出,我尝试将 showAlert 状态变量设置为 false,但这不起作用。有什么想法吗?
【问题讨论】:
标签: swiftui