1

When running the following code too often (e.g. every time a user enters text into a UISearchBar) it seems like the application stops servicing the requests. Does Apple have a burst limit on map requests? I also had one case where it blocked requests from my cloud database (through Parse), but nothing in the code below refers to the database so I don't believe those two are really related other than the fact that I'm probably sending too many requests concurrently. Does anyone have any insight into this?

MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = searchBar.text;

if(self.foundLocation) {
    request.region = MKCoordinateRegionMake(self.currentLocation.coordinate,MKCoordinateSpanMake(0.1,0.1));
}

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
self.localSearch = [[MKLocalSearch alloc] initWithRequest:request];

[self.localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error){       
    self.results = response;
    [self.tableView reloadData];
}];
nevan king
  • 112,709
  • 45
  • 203
  • 241
Jeff Nelson
  • 187
  • 1
  • 10
  • What's the evidence that "the application stops servicing the requests"? What's actually happening? – matt May 15 '14 at 22:59
  • Are you aware that your logic may be faulty? You are proceeding even if `self.foundLocation` is nil. That might not be what you want. – matt May 15 '14 at 23:00
  • Also, you are _testing_ `self.foundLocation`, but you are _using_ `self.currentLocation`. But how do you know the latter is not faulty? – matt May 15 '14 at 23:01
  • Also you are reloading the table without looking to see whether `response` is any good... – matt May 15 '14 at 23:03
  • @matt presumably the `foundLocation` was supposed to go into the search request to narrow it down but that part was omitted. – nevan king May 15 '14 at 23:05
  • @matt never mind, just read the code properly. – nevan king May 15 '14 at 23:06
  • @nevanking we can only go on the code he actually provided, and the code he actually provided doesn't make much sense – matt May 15 '14 at 23:08
  • @nevanking good use of superpowers :) – matt May 15 '14 at 23:08
  • The self.foundLocation was just a boolean test for checking when the current location is found. The problem happens not before this is set, but after (after sending multiple requests it stops responding). – Jeff Nelson May 15 '14 at 23:09
  • And in response to you, @matt. After a significant amount of requests it simply stops updating anymore until I restart the application. It also occasionally breaks other API requests elsewhere in the application, but it's possible that's a coincidence . – Jeff Nelson May 15 '14 at 23:10
  • @matt There's probably a location manager delegate method that's setting the `BOOL` for `foundLocation` _and_ setting `currentLocation` to whatever it finds. Either way, I think the problem is that he's hammering the server with requests every time a character is entered in the text field and getting refused, like the previous question. – nevan king May 15 '14 at 23:11
  • @JeffNelson I'd recommend you try the solution in this answer: http://stackoverflow.com/a/23626634/74118 that is checking whether a request is in progress and waiting until it finishes before starting another one. – nevan king May 15 '14 at 23:17
  • @nevanking Online I've found a lot of solutions that simply cancel the previous request, but this doesn't seem to fix the issue for me. Is it still problematic even if you cancel the previous request? Clearly it is, but I'm curious why this is. – Jeff Nelson May 15 '14 at 23:49

0 Answers0