Reachability is a strange problem

Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];

This line works fine on the device, but on the simulator I get a crash:

* Application termination due to the uncaught exception "NSInvalidArgumentException", reason: "+ [Reachability reachabilityWithHostName:]: unrecognized selector sent to the class

Does anyone know why?

+4
source share
2 answers

I had almost the same problem, except that the linker did not bind Reachability after I added it via pod.

 internetReachable = [Reachability reachabilityWithHostName:@"www.google.com"]; 

On this line, the compiler generated the error "Unknown class method for reachability of the selectorWithHostName:".

I tried to read accessibility, tried to clear the project, nothing helped. Then I just tried to rewrite this line and compile it!

 internetReachable = [Reachability reachabilityWithHostName:@"www.google.com"]; 

And now I understand why this worked. Since my old code was taken from another project with a different version of Reachability, and the selector was named "HostName", but new with "Hostname".

Before rewriting, I checked if this method has the Reachability method, and it seemed to me that it had one and I could not understand the problem. It turned out that I did not notice this small change in one letter!

+9
source

decided that I was updating Reachability, I was searching the Internet, and I found that somewhere someone had it before and just deleted the system configuration of the system and added it, cleared the project, and then builds again, and it works just fine on simulator and on the device

+3
source

Source: https://habr.com/ru/post/1387999/


All Articles