Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSURLConnection sendAsynchronousRequest在某些刷新请求上未命中完成处理程序_Ios_Objective C_Nsurlconnection_Uirefreshcontrol_Sendasynchronousrequest - Fatal编程技术网

Ios NSURLConnection sendAsynchronousRequest在某些刷新请求上未命中完成处理程序

Ios NSURLConnection sendAsynchronousRequest在某些刷新请求上未命中完成处理程序,ios,objective-c,nsurlconnection,uirefreshcontrol,sendasynchronousrequest,Ios,Objective C,Nsurlconnection,Uirefreshcontrol,Sendasynchronousrequest,我有这个代码块: +(void)requestPath:(NSString *)path onCompletion:(RequestCompletionHandler)complete { // Background Queue NSOperationQueue *backgroundQueue = [[NSOperationQueue alloc] init]; // URL Request NSURLRequest *request = [[NSUR

我有这个代码块:

    +(void)requestPath:(NSString *)path onCompletion:(RequestCompletionHandler)complete
{
    // Background Queue
    NSOperationQueue *backgroundQueue = [[NSOperationQueue alloc] init];

    // URL Request
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:path]
                                                  cachePolicy:NSURLCacheStorageAllowedInMemoryOnly
                                              timeoutInterval:10];

    // Send Request
    [NSURLConnection sendAsynchronousRequest:request
                                       queue:backgroundQueue
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
                               NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                               if (complete) complete(result,error);
                           }];


}
这段代码可以在我99%的使用时间内毫无问题地为我的应用程序提取数据。但是,有时(但并非总是)在UIRefreshControl刷新请求中,NSURLConnection sendAsynchronousRequest中的完成处理程序未命中,这会导致我的应用程序崩溃

我可能会请求相同的数据,有时会命中完成处理程序,但在刷新时,它将无法工作

我不知道为什么会这样

任何帮助都将不胜感激


谢谢

根据需要正确处理错误案例

 [NSURLConnection sendAsynchronousRequest:request
                                       queue:backgroundQueue
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
                               if (error)
                               {
                                   NSLog(@"%@",[error localizedDescription]);

                               }
                               else
                               {
                                   NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                                   //if (complete) complete(result,error);
                               }

                           }];