Reachability - strange issue

ぐ巨炮叔叔 提交于 2019-12-10 17:12:29

问题


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 ?


回答1:


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!




回答2:


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



来源:https://stackoverflow.com/questions/8634564/reachability-strange-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!