Reputation: 73
I'm currently doing this:
NSMutableDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL: [NSURL URLWithString:@"http://mysite/mypage.php"]];
Which is great, apart from when the data being returned is quite large, and it appears to time out. How could I get around this?
Thanks in advance.
Upvotes: 0
Views: 1375
Reputation: 34945
In convenience methods like initWithContentsOfURL
you have no control over things like timeouts. They are fine in my cases but it sounds like you will need to use the more low-level NSURLConnection
and NSURLRequest
to load data from the server. There are many examples on the net.
Upvotes: 0
Reputation: 2672
I'm not a big fan of using NSDictionary to manage downloads. I'd probably try something like:
NSURL *url = [NSURL URLWithString:@"http://mysite/mypage.php"];
NSURLRequest *request = [NSURLRequest requestWintURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
Now, if data is not NULL then save to local file. Then load the dictionary using the contents of that file using the initWithContentsOfFile: method.
If you still get the timeouts you can try larger timeoutIntervals.
Upvotes: 1