Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reachability - strange issue

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

This line works fine on device, but on simulator i get crash :

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[Reachability reachabilityWithHostName:]: unrecognized selector sent to class

Does anyone know why ?

like image 451
user784625 Avatar asked Dec 17 '22 05:12

user784625


2 Answers

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

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

In this line compiler was giving error 'No known class method for selector reachabilityWithHostName:'.

I tried to readd reachability, tried to clean project, nothing helped. Then I just tried to rewrite this line and it compiled!

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

And now I understand why it worked. Because my old code was taken from another project with other version of Reachability and selector was with 'HostName' but new one is with 'Hostname'.

Before rewriting I was checking if Reachability has this method and it seemed to me that it has and I couldn't understand the problem. It turned out that I didn't notice this small change in one letter!

like image 118
Denis Kutlubaev Avatar answered Dec 28 '22 07:12

Denis Kutlubaev


solved, I was upgrading Reachability, I searched the web and I found that somewhere someone had this before and just delete systemconfiguration framework and re add it, clean the project and then build again and it will work on both simulator and device perfectly

like image 32
user784625 Avatar answered Dec 28 '22 06:12

user784625