可达性 - 奇怪的问题

发布于 2024-12-23 01:04:48 字数 296 浏览 5 评论 0原文

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

这条线在设备上工作正常,但在模拟器上我崩溃了:

* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“+[ReachabilityreachabilityWithHostName:]:发送到类的无法识别的选择器

有人知道为什么吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七婞 2024-12-30 01:04:48

我遇到了几乎相同的问题,只是在我通过 pod 添加后链接器没有链接 Reachability。

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

在这一行中,编译器给出错误“没有选择器reachabilityWithHostName的已知类方法:”。

我尝试读取可达性,尝试清理项目,但没有任何帮助。然后我尝试重写这一行并编译它!

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

现在我明白为什么它有效了。因为我的旧代码是从具有其他版本的 Reachability 的另一个项目中获取的,并且选择器使用“HostName”,但新代码使用“Hostname”。

在重写之前,我正在检查 Reachability 是否有这个方法,在我看来它有,但我无法理解这个问题。原来我没有注意到这一封信的微小变化!

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!

栩栩如生 2024-12-30 01:04:48

解决了,我正在升级 Reachability,我搜索了网络,发现有人以前有过这个,只需删除系统配置框架并重新添加它,清理项目,然后再次构建,它将在模拟器和设备上完美运行

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文