NSURLConnection delegate method: didReceiveData not called …Why ?? (iPhone SDK)

孤人 提交于 2019-12-08 08:42:21

问题


Sample Code:

-(void)ConnectWithRequest:(NSMutableURLRequest*)req{

if(![req isEqual:theRequest]){
    [req retain];
    [theRequest release];
    theRequest = req;
}

XMLConnection = [[XMLWebServiceConnection alloc]init];  
Connection=[[NSURLConnection alloc]initWithRequest:theRequest delegate:XMLConnection];
}

In XMLConnection class I have implemented NSURLConnection delegate methods:

-(id)init{

    if(self=[super init]){
        receivedData = [[NSMutableData alloc]init]; //member of a class
    }
    return self;
}


- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    [receivedData release];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    [receivedData setLength:0]; 
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    [receivedData appendData:data]; 
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{

    NSString *theXML = [[NSString alloc] initWithBytes: [receivedData mutableBytes] length:[receivedData length] encoding:NSUTF8StringEncoding];

    NSLog(@"\nResponse printed :\n\n\n %@\n",theXML);

    [theXML release];

}

when i run this code,

method:

connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

didn't get called, any reason why this happens ? How to solve this problem ??


Thanks

来源:https://stackoverflow.com/questions/3923190/nsurlconnection-delegate-method-didreceivedata-not-called-why-iphone-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!