MKDirections many requests stop working

I need to draw a path starting with a list of coordinates (P1, P2, ... Pn). For each next pair of Pi, Pj of my list, I call the calculateDirectionsWithCompletionHandler method of MKDirections class to the Pn-1 element. The first time I call it, everything looks perfect. But if I call a second time or later, I get this error:

 Error Domain=MKErrorDomain Code=3 "Directions Not Available" UserInfo={NSLocalizedFailureReason=Route information is not available at this moment., MKErrorGEOError=-4, MKDirectionsErrorCode=2, NSLocalizedDescription=Directions Not Available} 

and nothing else works.

I think this is because I am calling the API too many times in a short time. I found on the Internet, I should use the direction.calculating attribute and check if the request is being executed. I can’t figure out how to use it. Can anybody help me? Thanks.

+5
source share

Source: https://habr.com/ru/post/1238866/


All Articles