0

I am facing the issues while fetching users location on Apple Watch. When I try to run on simulator I am not able to get the location but running on actual watch it returns me location. But there are some cases which don't return me location. Why does that happen?

Also, how should I do entries for location access in info.plist? Currently I have added to both iPhone and Apple Watch app.

This is how I request location.

func requestLocation() {
        guard !isRequestingLocation else {
            manager.stopUpdatingLocation()
            isRequestingLocation = false

            return
        }

        let authorizationStatus = CLLocationManager.authorizationStatus()

        switch authorizationStatus {
        case .notDetermined:
            print("notDetermined")
            isRequestingLocation = true
            manager.requestWhenInUseAuthorization()
        case .authorizedWhenInUse, .authorizedAlways:
            print("authorizedWhenInUse")
            isRequestingLocation = true
            manager.requestLocation()
            infoLabel.setText("Fetching Location...")
        case .denied:
            print("denied location")
        case .restricted:
            print("restricted location")
        }
    }

Below delegate method returns me location when found.

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        guard !locations.isEmpty else { return }

        DispatchQueue.main.async {
            self.currentLocation = locations.last!.coordinate
        }
    }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        DispatchQueue.main.async {
        print(error.localizedDescription)
            self.currentLocation = nil
        }
    }

    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        DispatchQueue.main.async {
            guard self.isRequestingLocation else { return }

            switch status {
            case .authorizedWhenInUse:
                manager.requestLocation()

            case .denied:
                print("Auth Denied")
                self.currentLocation = nil

            default:
                print("Auth Default")
                self.currentLocation = nil
            }
        }
    }
Parth Adroja
  • 13,198
  • 5
  • 37
  • 71
  • Did you ever get any resolution on this? I'm trying to make an app that accesses location on both phone & watch, and watch simulator complains when I don't have "privacy..." in watch info.plist, but refuses to install it if I do! As you say, works on real watch, with info.plist setting only on phone... – Grimxn Oct 01 '18 at 17:44
  • @Grimxn Still I haven't got any solution and it's been time I have looked on that issue. If you found anything do let me know. – Parth Adroja Oct 02 '18 at 14:35
  • @ParthAdroja I am looking for the same solution. Let me know if you guys have any solution? – Shahabuddin Vansiwala Mar 15 '19 at 07:25

0 Answers0