views:

15

answers:

3

Hi,

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.

A: 

NSURLRequest (or NSMutableURLRequest) and NSURLConnection.

tc.
A: 

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.

No one in particular
That sounds spot on! Can I just do something like [data saveToFile:filename] to save the data to a plist?Thanks again
fdf33
You're just using the NSData to store your download. If that's a plist then use it to dump to file and you have a plist file to work with.
No one in particular
A: 

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.

St3fan