[
SVProgressHUD
showWithStatus
:
@"
加载中
..."
];
NSURL *url = [NSURL URLWithString:stringUrl];
NSURLRequest
*request = [
NSURLRequest
requestWithURL
:url];
NSOperationQueue *operatonQueue = [ NSOperationQueue mainQueue ];
[ NSURLConnection sendAsynchronousRequest :request queue :operatonQueue completionHandler :^( NSURLResponse *response, NSData *data, NSError *connectionError) {
if (!connectionError) {
[ SVProgressHUD dismiss ];
NSOperationQueue *operatonQueue = [ NSOperationQueue mainQueue ];
[ NSURLConnection sendAsynchronousRequest :request queue :operatonQueue completionHandler :^( NSURLResponse *response, NSData *data, NSError *connectionError) {
if (!connectionError) {
[ SVProgressHUD dismiss ];
NSDictionary *cateDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
// 返回NSDictionay或者NSArray
} else {
[ SVProgressHUD showErrorWithStatus :[connectionError localizedDescription ]];
}
} else {
[ SVProgressHUD showErrorWithStatus :[connectionError localizedDescription ]];
}
}];
iOSTalk,分享iOS成长之路的点点滴滴。微信扫一扫即可关注。
本文介绍了一个iOS应用中使用NSURLConnection进行网络请求的例子,并展示了如何利用SVProgressHUD显示加载状态及错误提示。
225

被折叠的 条评论
为什么被折叠?



