标签:
NSData 同步下载
NSString * path = @"http://10.0.100.8/sns/my/user_list.php"; //转网址对象 NSURL * url = [NSURL URLWithString:path]; //转Data NSData * data = [NSData dataWithContentsOfURL:url]; if (data) { id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; //这是一个同步请求 请求和响应在一起 NSLog(@"%@",obj); } //同步下载会堵塞线程 主线程 --- 显示UI UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"进入主界面" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; [alert show];
NSConnection 同步下载
NSString * path = @"http://10.0.100.8/sns/my/user_list.php"; //转网址对象 NSURL * url = [NSURL URLWithString:path]; //转Data NSData * data = [NSData dataWithContentsOfURL:url]; if (data) { id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; //这是一个同步请求 请求和响应一气呵成 NSLog(@"%@",obj); } //同步下载会堵塞线程 主线程 --- 显示UI UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"进入主界面" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; [alert show];
标签:
原文地址:http://www.cnblogs.com/konglei/p/4830549.html