English 中文(简体)
NSURLConnection is not calls doFailWithError.
原标题:NSURLConnection is not calling didFailWithError.

I am attempting to write a bit of code that checks the URL of a datasource, then populates an array with objects from that URL. It actually works well, but if there is a problem with the web connection or the address I want to populate the array with data from a bundled file. The issue I am having is that the connection didFailWithError method is never called. I tried passing a simple string but it does not call. I want the app to still function for people who are using ipod touch or are in airplane mode.

<编码>接线的确是被动反应。

这是我所干的。

- (void)loadListData{
NSLog(@"Loading data from sources");

NSURLRequest *listURLRequest = [NSURLRequest requestWithURL:integerPhoneListURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1.0];
[[NSURLConnection alloc] initWithRequest:listURLRequest delegate:self];

  if (!listConnectFail){
        phoneListJSON =[NSData dataWithContentsOfURL:integerPhoneListURL];
        [self performSelectorOnMainThread:@selector(fetchedData:) withObject:phoneListJSON waitUntilDone:YES];


    } else {
        //This will tell us if there is an error loading the file
        NSLog(@"File not found on web init from file");
        phoneListJSON =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"contactlist" ofType:@"json"]];
        [self performSelectorOnMainThread:@selector(fetchedData:) withObject:phoneListJSON waitUntilDone:YES];
    }



//Initialize the filtered list with array of customer objects. Based on original data
filteredList = [[NSMutableArray alloc] init];

for (NSDictionary *dict in phoneListOriginal) {
    contact *single = [[contact alloc] init];
    single.fName = [dict objectForKey:@"fName"];
    single.lName = [dict objectForKey:@"lName"];
    single.extension = [dict objectForKey:@"extension"];
    single.title = [dict objectForKey:@"title"];
    single.department = [dict objectForKey:@"department"];
    single.cellNumber = [dict objectForKey:@"cellNumber"];
    //NSLog(@"%@", single.lName);
    [filteredList addObject:single];
}


NSLog(@"Array filteredLIst contains %d records",[filteredList count]); }

-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{

listConnectFail = YES; 
NSLog(@"Connection Failed, pulling from file"); }

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { listConnectFail = NO; NSLog(@"Connection Succeeded, populating from API"); }

我知道,我可能不看到,这是一件 st事,但我可以利用帮助看看我看不到什么。

提前感谢!

问题回答

你怎样确认贵代表没有收到信息? 您是否检查了记录?

你的法典似乎假定名单Connect 旅行将紧接着进行国家措施,不一定是这种情况。

[[NSURLConnection alloc] initWithRequest:listURLRequest delegate:self];
if (!listConnectFail){...}

The NSURLConnection documentation states that The delegate will receive delegate messages as the load progresses.

然而,我不相信飞机方式,也许可以同步发现这一特殊错误。





相关问题
Separating Business Layer Errors from API errors

The title is horrible, i know; I m terrible at titles on SO here. I m wondering what would be the best way to present unified error responses in a webapi when errors could be raised deep inside the ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

How to tell why a file deletion fails in Java?

File file = new File(path); if (!file.delete()) { throw new IOException( "Failed to delete the file because: " + getReasonForFileDeletionFailureInPlainEnglish(file)); } Is there a ...

Exceptions: redirect or render?

I m trying to standardize the way I handle exceptions in my web application (homemade framework) but I m not certain of the "correct" way to handle various situations. I m wondering if there is a ...

热门标签