Tag: sendasynchronousrequest

connectionDidFinishLoading:不使用[NSURLConnection sendAsynchronousRequest:queue:completionHandler:

我想用NSMutableURLRequest启动一个请求,当[NSURLConnection sendAsynchronousRequest的答案:获得一个好的状态码。 当我单独启动包含NSMutableURLRequest的executeForStatusOkMetod时,它完美地工作。 但是,如果我用[NSURLConnection sendAsynchronousRequest:]启动executeForStatusOkMetod , connectionDidFinishLoading:函数永远不会被调用。 这里是主要的代码: NSOperationQueue *myQueue = [[NSOperationQueue alloc] init]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]]; request.timeoutInterval = 10; [NSURLConnection sendAsynchronousRequest:request queue:myQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; NSLog(@"response status code: %ld, error status : %@", (long)[httpResponse statusCode], error.description); if ((long)[httpResponse statusCode] >= […]

在iOS中使用sendAsynchronousRequest:request API处理401状态码

我正在使用这种方式的API来login我的应用程序。 NSString *url = [NSString stringWithFormat:@"%@//login",xyz]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error]; if (!jsonData) { NSLog(@"Error creating JSON object: %@", [error localizedDescription]); } [request setValue:@"application/json;charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [request setValue:APIKEY forHTTPHeaderField:@"X_API_KEY"]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:jsonData]; [NSURLConnection sendAsynchronousRequest:request // the NSOperationQueue upon which the handler block will be dispatched: […]

错误消息:从公共有效用户设置和系统组容器中读取systemgroup.com.apple.configurationprofilespath为

当我使用下面的代码时,我有错误消息: [NSURLConnection sendAsynchronousRequest:request queue:myQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; NSLog(@"response status code: %ld, error status : %@", (long)[httpResponse statusCode], error.description); if ((long)[httpResponse statusCode] >= 200 && (long)[httpResponse statusCode]< 400) { // do stuff [self requestFunction]; //Web Service } }]; 错误消息: 2017-02-27 01:13:30.088641 RENAULT[210:12313] [MC] System group container […]

处理多个NSURL连接的最佳方法

我正在尝试以编程方式创build一个xls表单。 为了填写表格,我使用了100多个NSURLConnection 。现在,我的方法是: build立连接并将数据存储到数组中。 这个数组有100个对象。 现在取第一个对象并调用连接。 存储数据。 并使第二个对象在数组中的第二个连接。 这一直持续到数组中的最后一个对象。 平均需要14秒才能完成100个连接。 有什么办法来实现NSURLConnection以更快的方式获得响应? 直到昨天我遵循的基本方法,如: 声明属性: @property (nonatomic,strong) NSURLConnection *getReportConnection; @property (retain, nonatomic) NSMutableData *receivedData; @property (nonatomic,strong) NSMutableArray *reportArray; 在viewDidLoad初始化数组: reportArray=[[NSMutableArray alloc]init]; 在button操作中初始化NSURLConnection : /initialize url that is going to be fetched. NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"****/%@/crash_reasons",ID]]; //initialize a request from url NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; […]

在iOS上,如何使cell.imageView刷新其内容?

我在tableView:cellForRowAtIndexPath尝试通过调用设置图像 [self downloadImage:urlString andSetIntoCellImageView:cell] 在downloadImage ,它将调用NSURLConnection:sendAsynchronousRequest (仅适用于iOS 5及更高版本),并在完成块中通过使用设置图像 cell.imageView.image = [UIImage imageWithData:data]; // data is downloaded data 它工作,如果在tableView:cellForRowAtIndexPath , imageView填充一个虚拟的占位符图像 – 我不知道如何刷新新的图像,是由setNeedsDisplay做一个重绘? 但是,如果我不设置占位符图像,那么新的图像将不会显示。 我不知道可以使用什么机制来显示图像? 如果我使用 [cell.imageView setNeedsDisplay] 要么 [cell setNeedsDisplay]; 在完成块,它将无法正常工作,如果我使用 [self.table reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 通过使downloadImage接受indexPath完成块,它将再次调用tableView:cellForRowAtIndexPath ,并导致无限循环。 所以好像我需要使用一些哈希表来记住图像是否已经在哈希表中:如果没有,调用downloadImage ,如果在哈希表中,只需使用它,所以不会有无限循环。 但有没有一种简单的方法来使图像显示出来? 设置一个占位符图像的作品,但如果我们不 – 通过什么机制的占位符导致图像刷新?