I have a watchOS app that shows a map with the device's current location. This works as expected on a simulator.
On a device in TestFlight, the map shows for an instant, but then the map area turns blue.
When I zoom in and out, again, the correct map shows for an instant, but then the screen turns blue.
I have a couple of images to illustrate the issue:
I'm attaching the mapping code below:
super.awake(withContext: context)
if CLLocationManager.locationServicesEnabled() {
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.startUpdatingLocation()
} else {
print("Problem with permissions")
return
}
let span = MKCoordinateSpan(
latitudeDelta: 0.005,
longitudeDelta: 0.005
)
#if targetEnvironment(simulator)
let location = CLLocationCoordinate2D(
latitude: simulatorLatitude,
longitude: simulatorLongitude
)
let region = MKCoordinateRegion(center: location, span: span)
mapView.setRegion(region)
mapView.addAnnotation(location, withImageNamed: "mapPinRed", centerOffset: CGPoint(x: 0, y: 0))
#else
locationManager.requestLocation()
#endif
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
}
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
print(#function, "Status: ", status.rawValue)
if status.rawValue == 0 {
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let currentLocation = locations[0]
let lat = currentLocation.coordinate.latitude
let long = currentLocation.coordinate.longitude
self.mapLocation = CLLocationCoordinate2DMake(lat, long)
//let span = MKCoordinateSpan.init(latitudeDelta: 0.1, longitudeDelta: 0.1)
let region = MKCoordinateRegion.init()
self.mapView.setRegion(region)
self.mapView.addAnnotation(self.mapLocation!, with: .red)
}
func centerMapOnLocation(location: CLLocation) {
#if targetEnvironment(simulator)
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: simulatorLatitude, longitude: simulatorLongitude), span: MKCoordinateSpan(latitudeDelta: CLLocationDegrees(zoomValue), longitudeDelta: CLLocationDegrees(zoomValue)))
DispatchQueue.main.async {
self.mapView.setRegion(region)
}
#else
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude), span: MKCoordinateSpan(latitudeDelta: CLLocationDegrees(zoomValue), longitudeDelta: CLLocationDegrees(zoomValue)))
DispatchQueue.main.async { [self] in
self.mapView.setRegion(region)
self.mapView.addAnnotation(location.coordinate, withImageNamed: "mapPinRed", centerOffset: CGPoint(x: 0, y: 0))
}
#endif
}
My permissions are set in Watch.extension info.plist as follows:
Privacy - Location Always Usage Description
Privacy - Location Always and When In Use Usage Description
Privacy - Location Usage Description
I would appreciate any help.