Why do I get an MKErrorDomain error when doing a local search?

后端 未结 1 1717
悲&欢浪女
悲&欢浪女 2021-01-22 13:50

I am trying to implement a search bar where the user can type in a string and search for an address or a business.

To find businesses I use Yelp APIs to outsource the in

相关标签:
1条回答
  • What you're seeing here is the MKError.loadingThrottled error. You will have to delay requests you're sending to Apple.

    You can do this by restarting a timer every time the user updates the search query. You can adjust how frequently you ping the API by extending the length of the timer. By resetting the timer each time the query is updated, you avoid sending multiple requests when the characters are changing rapidly.

    // declare and store Timer somewhere
    
    func searchAddress(with query: String) {
    
    }
    
    func timerDidFire(_ sender: Any) {
        let query = textField.text
        searchAddress(with: query)
    }
    
    Timer.scheduledTimerWithTimeInterval(0.5, target: self, selector: #selector(timerDidFire), userInfo: nil, repeats: false)
    
    0 讨论(0)
提交回复
热议问题