I am new to web services. I need to get information from a .NET web server. For this, I use 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 can get the information, but I need to check it. If there is no connection, I need to start Alertview. For this, 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 deleting the connection. But it does not cause any warnings. After a while, it will display Error in connectionin the console. But it takes a lot of time. Is there any other possibility besides this? How to display a warning when there is no connection?
Can anybody help me?
source
share