I am new to web services. I need to get information from .NET web server. For that I am using the following code:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
if (data) {
NSLog(@" bcxbm,xcm,xcmcmx,b data consist %@",data);
}
else {
NSLog(@"not exist");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"<Alert message>" delegate:self cancelButtonTitle:@"Retry" otherButtonTitles:@"Cancel", nil];
[alert show];
[alert release];
}
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
I am able to get information, but I need to validate it. If there is no connect, I need to fire an Alertview
. For that I have the code:
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
if (data) {
NSLog(@" bcxbm,xcm,xcmcmx,b data consist %@",data);
}
else {
NSLog(@"not exist");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"<Alert message>" delegate:self cancelButtonTitle:@"Retry" otherButtonTitles:@"Cancel", nil];
[alert show];
[alert release];
}
}
I check by removing connection. But it does not fire any alerts. After some time, it displays Error in connection
in console. But it takes much time. Is there any other possibility than this? How to display alert when there is no connection?
Can anyone please help me?