开发者

nsdata ERROR if no data at the URL

hi i have the below code tryinh to get the image data but sometimes there is no image at the URL and the app is crashing beca开发者_StackOverflow社区use NSData is not throwing exception. how can we have a timer so we can abort the get data operation is it takes longer.

tempData=[NSData dataWithContentsOfURL:[NSURL URLWithString:(NSString *)nextCatchItem.imageLink]];              

thanks in adavnce


Don't use -dataWithContentsOfURL: unless the URL is a file:// URL. This executes a synchronous fetch, which is a horrible idea on the main thread, and on background threads it's simply a poor idea (as there's no error reporting). Instead you should use NSURLConnection, ideally with the asynchronous API, or with the synchronous API if you're running on a background thread.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜