Pregunta

The problem is I have these messages :

  • host not found
  • a server with a specified hostname could not be found
  • network is not available

Especially the second message it shows for a second and then everything become working

So what I want is to know how to find these msgs and how to handle them and put my message instead of them or just make another action instead of showing them like the facebook app , when the connection down it shows a red alert with label "network error"

How can I do this?

¿Fue útil?

Solución 3

finally i found the solution and its like this

-(void)handleError:(NSError*)error{
SEL onerror = @selector(onerror:);
if(self.action != nil) { onerror = self.action; }
if([self.handler respondsToSelector: onerror]) {
    if (error.code == -1003 || error.code == -1001 || error.code == -1004) { //check all kind of errors
        [self send];
    }else{
    [self.handler performSelector: onerror withObject: error];
    }
} else {
    if(self.defaultHandler != nil && [self.defaultHandler respondsToSelector:onerror]) {
        [self.defaultHandler performSelector:onerror withObject: error];
    }
}
if(self.logging) {
    NSLog(@"Error: %@", error.localizedDescription);
}

}

Otros consejos

Why not using Reachability test in Your Code ?

You can find Sample Code from Apple Developer portal. Link : https://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

Code:

 Reachability *reachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus internetStatus = [reachability currentReachabilityStatus];

    if (internetStatus != NotReachable) {


      // Do Your Stuff As Internet Available        

    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"We are unable to make a internet connection at this time. Please try again later" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];


    }

You can check your error and then convert in your custom error message using stringByReplacingOccurrencesOfString method

NSString *str = @"server with a specified hostname could not be found";

if ([yourErrorMsg isEqualToString:str])
{
    NSString *customError = [yourErrorMsg stringByReplacingOccurrencesOfString:str withString:@"Your Custom String"];
    NSLog(@"New custom error = %@",customError);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top