1

In viewDidLoad, I call reverseGeocodeLocation to get geo info. but It is async API and I need a sync flow. However, I could not sync this flow. because when I inject semaphore in the flow, reverseGeocodeLocation's completion handler is not working in forced sync flow case. (I used semaphore for sync). It just stopped and completionHandler is not invoked. What should I do? Thanks to read. The code below is my sample.

let location = CLLocation(latitude: latitude, longitude: longitude)
  
  let semaphore = DispatchSemaphore(value: 0)
  
  CLGeocoder().reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in
    print("completion")
    var placeMark: CLPlacemark! = placemarks?.first
    
    semaphore.signal()
  })
  semaphore.wait()

Comment it myself. It's impossible to use reverseGeocodeLocation synchronous.

The link below (Apple public) it explain.

https://developer.apple.com/documentation/corelocation/clgeocoder/1423621-reversegeocodelocation

Geocoding requests are rate-limited for each app, so making too many requests in a short period of time may cause some of the requests to fail. When the maximum rate is exceeded, the geocoder passes an error object with the value CLError.Code.network to your completion handler.

Songwon Park
  • 125
  • 1
  • 11
  • what you exactly want to achieve ? – Jawad Ali Jun 19 '20 at 06:33
  • its not a good idea to use `DispatchSemaphore` or `dispatchGroup` for one `reverseGeocodeLocation` async call ... just update on results ... – Jawad Ali Jun 19 '20 at 06:35
  • I want to get a local photo(having location degree) list when view did load case initailly load. It's not a normal pattern? I'm a newbie ios developing. – Songwon Park Jun 19 '20 at 06:40

0 Answers0