didReceiveData未被调用

didReceiveData未被调用

本文介绍了connection:didReceiveData未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NSURLConnection中遇到问题。我的didRecieveData方法没有被调用。我不知道是什么问题。我也经历了几乎所有以前的问题,但似乎没有解决。

I am having a problem in NSURLConnection. My didRecieveData method is not being called . I dont know what's the problem. I also went through almost all the previous problems but nothing seems to solve.

请帮助我。
这是我的代码。

Please help me out.This is my code.

      -(void)gettheJSONdata
     {
           NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:_serverAddress cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];

           [request setHTTPMethod: @"GET"];

           NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

          NSLog(@"This is displayed");
     }

     -(void)connection:(NSURLConnection*)connection didReceiveData:(NSData *)data
     {
           NSLog(@"This is not displayed.");
           AppAppDelegate *JSONdata = (AppAppDelegate*)[[UIApplication sharedApplication] delegate];

           JSONdata.userloginJSONdata = [[NSData alloc] initWithData:data];

           NSError *error;

          _result = [NSJSONSerialization JSONObjectWithData:JSONdata.userloginJSONdata options:NSJSONReadingMutableContainers error: &error];

           NSString *test = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
           NSLog(@"Json data : %@",test);
     }

     -(void) connectionDidFinishLoading:(NSURLConnection*) connection
     {
           AppAppDelegate *resultofJSONdata = (AppAppDelegate*)[[UIApplication sharedApplication] delegate];

           resultofJSONdata.JSONdataresult = _result;
      }


推荐答案

最后我解决了这个问题。
我没有合成JSONdataresult。

Finally I solved the problem.I didnt synthesize the JSONdataresult.

我没有意识到这可能会导致NSURLConnection出现问题。

I didn't realise that this could cause a problem with NSURLConnection.

这篇关于connection:didReceiveData未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 18:33