如何在 Objective-C 中验证网络连接
我正在查看developer.apple.com 上的Reachability 示例项目,发现这是一个大型项目,只是为了验证您是否具有网络连接。
问题的第一部分是“确定设备是否可以连接 3G 或 WiFi 网络所需的最低代码是什么?”
接下来,这应该在 appDelegate 内部(启动时)还是在启动的第一个视图控制器内完成?
先感谢您
I was looking over the Reachability sample project on developer.apple.com and found that it was a large project just to verify you had network connectivity.
First part of the question is "What is the minimum code required to find out if the device can reach a 3G or wifi network?"
And next should this be done inside the appDelegate (on start) or inside the first View Controller that is launched?
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它并不大,它确实可以满足您的要求。如果它对您来说太大,您可以只提取您需要的内容,例如reachabilityForLocalWiFi。但恐怕也不会小很多。
是的,您可以在应用程序委托中或第一个视图控制器内使用可达性。
Reachability 通知注册……
回调方法示例……
不要忘记停止通知、移除观察者并释放 rechability 对象。
It's not large, it really does what you want. If it is too big for you, you can extract what you need only like reachabilityForLocalWiFi. But I'm afraid that it will not be much smaller.
Yes, you can use reachability in your application delegate or inside the first view controller.
Reachability notification registration ...
... callback method example ...
... do not forget to stop notifications, remove observer and release rechability object.