iOS App Getting Throttled from Local Searches

iOS app getting throttled from local searches

Autocompletion requires a special APIs. MapKit doesn't offer such an interface. Just firing off dozens of requests to the normal search API causes a tremendous load.

You basically have two options:

  1. Go with Google Places. They have a dedicated Places Autocompletion API. There is even a complete library for iOS on GitHub.

  2. Reduce the number of requests, e.g. by only sending a request if the user has paused typing for 300ms and only if no earlier request is outstanding. But that's still no guarantee that Apple won't throttle your requests.

How to throttle search (based on typing speed) in iOS UISearchBar?

Thanks to this link, I found a very quick and clean approach. Compared to Nirmit's answer it lacks the "loading indicator", however it wins in terms of number of lines of code and does not require additional controls. I first added the dispatch_cancelable_block.h file to my project (from this repo), then defined the following class variable: __block dispatch_cancelable_block_t searchBlock;.

My search code now looks like this:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if (searchBlock != nil) {
//We cancel the currently scheduled block
cancel_block(searchBlock);
}
searchBlock = dispatch_after_delay(searchBlockDelay, ^{
//We "enqueue" this block with a certain delay. It will be canceled if the user types faster than the delay, otherwise it will be executed after the specified delay
[self loadPlacesAutocompleteForInput:searchText];
});
}

Notes:

  • The loadPlacesAutocompleteForInput is part of the LPGoogleFunctions library
  • searchBlockDelay is defined as follows outside of the @implementation:

    static CGFloat searchBlockDelay = 0.2;

How to do a local search autocomplete as Apple's native map app does?

MkLocalSearchRequest will not perform auto complete on your search string, perhaps because Apple wants to limit the number of requests from 3rd party apps.

In theory you could reverse-engineer the requests and responses to https://gsp-ssl.ls.apple.com/auto_complete.arpc and then perform those requests yourself, not using MkLocalSearchRequest at all. But that would probably lead to your app being rejected on the App Store.

How to get estimated time of arrival to multipe destinations on iOS?

Hi investigate class MKRoute this class contains all information you need.

This object contains

expectedTravelTime

Also you should consider LoadingThrottled

The data was not loaded because data throttling is in effect. This
error can occur if an app makes frequent requests for data over a
short period of time.

For prevent your request from bing throttled, reduce number of requests.
Try to use Completion Handlers to know if you request is finished and only after send another request or cancel previous. From my experience try to handle this request just as regular network request just be sure you are not spamming unnecessary requested to the Apple API. But this is not 100% guarantee that Apple won't throttle your requests.



Related Topics



Leave a reply



Submit