iOS15 LocationButton
エラー発生
- iOS15から導入された「LocationButton」普通に書くと
[Error Domain=kCLErrorDomain Code=1 "(null)]
が出る
結局、「requestLocationAuth()」とPlistへのお約束が必要だった(XCode13にはデフォルトないけど)
確認するには「stopLocation()」で一回update Locationを止めて確認する
LocationButton
class LocationButtonViewModel: NSObject, ObservableObject, CLLocationManagerDelegate {
//その他省略
func requestLocation() {
locationManager.requestLocation()
}
func stopLocation() {
locationManager.stopUpdatingLocation()
}
func requestLocationAuth(man: CLLocationManager) {
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyReduced
switch man.authorizationStatus {
case .authorizedAlways:
locationStatus = "authorized always"
checkLocationAccuracyAllowed()
case .authorizedWhenInUse:
locationStatus = "authorized when in use"
checkLocationAccuracyAllowed()
case .notDetermined:
locationStatus = "not determined"
case .restricted:
locationStatus = "restricted"
case .denied:
locationStatus = "denied"
default:
locationStatus = "other"
}
}
}
struct ContentView: View {
@ObservedObject var model = LocationButtonViewModel()
var body: some View {
LocationButton(.currentLocation) {
locationVM.requestLocation()
}
LocationButton
class LocationButtonViewModel: NSObject, ObservableObject, CLLocationManagerDelegate {
//その他省略
func requestLocation() {
locationManager.requestLocation()
}
func stopLocation() {
locationManager.stopUpdatingLocation()
}
func requestLocationAuth(man: CLLocationManager) {
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyReduced
switch man.authorizationStatus {
case .authorizedAlways:
locationStatus = "authorized always"
checkLocationAccuracyAllowed()
case .authorizedWhenInUse:
locationStatus = "authorized when in use"
checkLocationAccuracyAllowed()
case .notDetermined:
locationStatus = "not determined"
case .restricted:
locationStatus = "restricted"
case .denied:
locationStatus = "denied"
default:
locationStatus = "other"
}
}
}
struct ContentView: View {
@ObservedObject var model = LocationButtonViewModel()
var body: some View {
LocationButton(.currentLocation) {
locationVM.requestLocation()
}
Author And Source
この問題について(iOS15 LocationButton), 我々は、より多くの情報をここで見つけました https://qiita.com/nekoman/items/33ecc6b5c00c631d3e8c著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .