开发者

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:

  1. You're using a deprecated method which will most likely be removed on future SDK versions, and;
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜