可达性-奇怪的问题 [英] Reachability - strange issue

查看:54
本文介绍了可达性-奇怪的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

此行在设备上工作正常,但是在模拟器上我崩溃了:

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

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

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

有人知道为什么吗?

推荐答案

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

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"];

在这一行中,编译器给出错误选择器可达性没有未知的类方法HostHostName:".

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"];

现在我明白了它为什么起作用了.因为我的旧代码来自具有其他版本的Reachability的另一个项目,而选择器使用的是"HostName",而新代码使用的是"Hostname".

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!

这篇关于可达性-奇怪的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆