下面是代码。在这里,LocationManager 是 Observable 类,我在其中将“locationStatus”属性标记为@Published。现在,我想要实现的是当用户看到位置弹出窗口并授予位置访问权限时,它应该导航到下一个屏幕。有人可以帮我解决这个问题吗?提前致谢
struct MyLocationScreen: View {
@ObservedObject var locationManager = LocationManager()
@State var isShowLinkTarget :Bool = false
var body: some View {
NavigationView{
ZStack{
Button(action: {
let locStatus = self.locationManager.locationStatus
if locStatus == .authorizedWhenInUse || locStatus == .authorizedAlways {
self.showLinkTarget = true
} else {
self.locationManager.requestAuthorization()
self.locationManager.startUpdate()
}
}) {
Text("Share Location")
}
NavigationLink(destination: NextScreen(), isActive: $showLinkTarget) {
Text("")
}
}
}
}
}