There are no built-in functions to handle this that I know of. I started using the following solution. I apologize to Swift, I am not fluent in Objective-C.
This will give you a 2 second timeout
func myLookupFunction(location: CLLocation) { let timer = NSTimer(timeInterval: 2, target: self, selector: "timeout:", userInfo: nil, repeats: false); geocoder.reverseGeocodeLocation(location){ (placemarks, error) in if(error != nil){ //execute your error handling } else { //execute your happy path } } NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSDefaultRunLoopMode) } func timeout(timer: NSTimer) { if(self.geocoder.geocoding) { geocoder.cancelGeocode(); } }
After the timeout is triggered, a callback is made and the path to the error is called.
You will receive an error message:
- Code = 10
- Localized description (in English) = operation could not be completed. (error kCLErrorDomain 10.)
Hope this helps.
Jtango18
source share