Checking for NSURL load done
I'm looki开发者_开发知识库ng for a "did finish, or finish" thing in NSURL -> NSstring initWithContentsOfUrl
I found "URLResourceDidFinishLoading" but this seems to be depreciated
I couldn't find any but maybe I searched for the wrong thing.
If you're talking about -initWithContentsOfURL:
from NSString
, it has been deprecated.
But even if you are using it, it's a synchronous method - meaning your code will halt until the data has been loaded into the resulting NSString
object:
NSURL *url = [NSURL URLWithString:@"http://google.com"];
NSString *htmlData = [NSString stringWithContentsOfURL:url];
NSLog(@"%@", htmlData); // you have your data loaded here, synchronously.
So, just to be clear: this is a bad practice for two reasons:
- You're using a deprecated method which will most likely be removed on future SDK versions, and;
- You're freezing your UI while loading something from the network, while giving no feedback to the user whatsoever.
What you need is probably NSURLRequest
to create your request object and NSURLConnection
to actually load it from the network.
精彩评论