Reputation: 3074
I am about to release multiple Apps, and I have one issue that I know I want to address before release. When I make an API call and never receive a response, my Apps will not be able to function. They are very dependent on having internet access to function at all. How do I setup some form of delay before I send another call? How do I decide how long I need to wait as many of the API calls vary in timelines of their normal response times?
I am definitely most interested in best practices, but am slightly confused as to any good method of doing this in that when you don't receive a response, there is no trigger. I suppose I could setup a timestamp and check the difference between if and a timestamp of now using an NSTimer... but is this even a good way of handling this? Most methods I can currently think of feel bulky and wrong.
Upvotes: 0
Views: 45
Reputation: 5076
Take a look at Grand Central Dispatch and DispatchSemaphore
s (in swift 3). You can use semaphores to wait for an operation to complete with a specified timeout. If the operation doesn't complete normally and it times out it will give you a specific result which you can then use to handle it in your code.
Upvotes: 1