user784625
user784625

Reputation: 1938

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 ?

Upvotes: 4

Views: 1358

Answers (2)

Denis Kutlubaev
Denis Kutlubaev

Reputation: 16114

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!

Upvotes: 9

user784625
user784625

Reputation: 1938

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

Upvotes: 3

Related Questions