动态信息屏幕
我正在尝试找到一种方法,如果互联网连接可用,则可以从网络下载我的应用程序上的信息屏幕(这样我就可以定期更新它)。 如果互联网不可用,则应使用默认的或最后下载的。 这可能吗?
I am trying to find a way to make the info screen on my app download from the web IF an internetconnection is available (so i can update it regularly). If internet is not available, it should use the default or the last downloaded one. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意上面 James Skitmore 提供的方法是测试连接性的糟糕方法。 请不要使用它。 它将不必要地加载 google.com,并且如果网络不可用,则会导致超时,这将使您的应用程序看起来像是已冻结。
以下是检查网络连接的方法。
在您的应用程序中,您可以执行此操作来检查网络是否可用:
您现在还可以检查与特定主机的连接,例如 yourwebsite.com,或者您可以检查连接类型、3G 与 Wifi 等。让您通过阅读头文件自己弄清楚这一点。
您需要将以下文件包含到您的应用程序中:
(由 Erica Sadun 提供)
UIDevice-Reachability.h
UIDevice-Reachability.m
wwanconnect.h
wwanconnect.c
Please note the method offered by James Skitmore above is a terrible way to test connectivity. Please do not use it. It will unnecessarily load google.com, and it will cause a timeout should the network not be available, which will make your app look like it has frozen.
Here's how you could check for net connectivity.
In your app, you can do this to check for whether network is available:
You can now also check connectivity to a certain host, such as yourwebsite.com, or you could check for the type of conenction, 3G vs Wifi, etc. I'll let you figure this out yourself by reading the header files.
You're going to need to include the following files to your app:
(courtesy of Erica Sadun)
UIDevice-Reachability.h
UIDevice-Reachability.m
wwanconnect.h
wwanconnect.c