Question

I am calling an API for fetching contacts :

requestContacts = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.example.com/contacts"]
                                               cachePolicy:NSURLRequestReloadIgnoringCacheData
                                           timeoutInterval:60] ;

It returns only some contacts because of paging. The connection response has a field :

Link = "<http://www.example.com/contacts?page=2>; rel=\"next\", <http://www.example.com/contacts?page=19>; rel=\"last\"";

How can I get all the contacts? Should I make calls in loop by specifying the page number or there is any other way?

Was it helpful?

Solution

If you have control over http://www.example.com server please create REST api or so for accessing data from this server. Even if you apply some looping trick to fetch all contacts that server may change some loading on that HTML page and your code will fail. So my suggestion is add service to http://www.example.com which will give you array of contacts (best way will be JSON array - as Obj provides built in library for parsing JSON) also you can add more functionality to this by adding limit parameter, filtering in REST API itself

Hope it helps !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top