我在NSURLConnection有問題。我的didRecieveData方法沒有被調用。我不知道有什麼問題。我也經歷了幾乎所有以前的問題,但似乎沒有解決。連接:didReceiveData不叫
請幫我一把。 這是我的代碼。
-(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;
}
到你頭文件你加'NSURLConnectionDelegate'協議? –
是... @interface主幹:NSObject 這樣... –
khushalbokadey
頭文件中的協議不會影響任何內容。真正的問題是,是否是NSURLConnection的代表?我假設它是...因爲我猜測connectionDidFinishedLoading:被擊中,對吧? – Christian