iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐰

Beware of Excessive Requests and Throttling in MKLocalSearch

に公開

MKLocalSearch allows you to search for map feature information provided by Apple Maps without a map view. Apple's servers return information such as feature names and latitude/longitude in response to requests.

However, this API has limitations, and if requests are concentrated in a short period, it may return an error. Although it doesn't seem to be mentioned much in the documentation, specifically, the server returns an error if more than 50 requests are made within 60 seconds.

When this happens, the following error is output to the Xcode console:

Throttled "PlaceRequest.REQUEST_TYPE_SEARCH" request: Tried to make more than 50 requests in 60 seconds, will reset in 14 seconds -
Error Domain=GEOErrorDomain
Code=-3 "(null)"
UserInfo={
	details=(
		{
			intervalType = short;
			maxRequests = 50;
			"throttler.keyPath" = "app:<BUNDLE_IDENTIFIER>/0x20301/short(default/any)";
			timeUntilReset = 14;
			windowSize = 60;
		}
	),
	requestKindString=PlaceRequest.REQUEST_TYPE_SEARCH,
	timeUntilReset=14,
	requestKind=769
}

I have formatted the contents of UserInfo for clarity, but the error information is included in a Dictionary<String : Any> format object.

However, the error object that can be caught in Swift code is not this information (GEOErrorDomain), but a different, simpler error object called MKErrorDomain. Therefore, it seems difficult to build any logic or functionality using the information appearing in the console.

Furthermore, this limitation seems to be measured at least on a per-app basis. The <BUNDLE_IDENTIFIER> part contains the actual bundle ID of the app. I have not fully investigated whether this is measured "per-app" even when requests are made from multiple devices simultaneously, or if it is measured independently for each device even for the same app (i.e., per instance).

(For example, if the 0x20301 part of throttler.keyPath represents a unique identifier for the user environment's instance or device, then this may not be a major concern.)


For now, the workarounds are as follows:

  • Create a mechanism to avoid sending many requests in a short period (Guideline: a maximum of 50 requests per 60 seconds).
  • Do not rely on the detailed information included in the error.
  • If an error occurs, wait for several dozen seconds.

Discussion