iPhone SDK Internet连接检测 [英] iPhone SDK Internet connection detection

查看:123
本文介绍了iPhone SDK Internet连接检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 iPhone 应用程序,该应用程序可以调用一些Web服务。我在Apple商店发布了这个应用程序,但它被拒绝(这是正确的),因为如果没有可用的Internet连接,则没有向用户显示错误消息。很明显,如果没有它,应用程序将无法运行。

I'm working on an iPhone application that makes a few calls to web services. I posted this application on the Apple store but it got rejected (and rightly so) since there was no error message displayed to the user if no Internet connection is available. Since obviously the application would not work without it.

所以我只是想知道如何最好地实现这一目标?我猜测需要在 viewDidLoad 方法中添加一些警告框,说明你需要一个Internet连接才能使用这个应用程序。

So I just wanted to know how to best achieve this? I'm guessing something needs to go in the viewDidLoad method that will throw an alert box saying something like "You need an Internet connection to use this application".

任何想法都将受到赞赏。

Any ideas would be appreciated.

推荐答案

如果您的应用程序必须具有网络访问权限最简单的方法是将以下设置作为布尔值添加到info.plist。

If your application must have network access the easiest way is to add the following settings to your info.plist as boolean values.


  • SBUsesNetwork - 确保设备处于活动状态连接(编辑:不适用,这似乎是某人在某些时候发现的私有API。它不在Apple的开发者文档中。)

  • UIRequiresPersistentWiFi - 确保设备是通过WiFi连接

  • SBUsesNetwork - Ensure the device has an active connection ( not applicable, this seems to be a private API someone found at some point. It is not in Apple's developer documentation.)
  • UIRequiresPersistentWiFi - Ensures the device is connected via WiFi

如果您的选择不正确,则在启动您的应用程序时将向用户显示相应的消息。最重要的是,这个消息来自操作系统,因此是本地化的。

If your choice is not true then the user will be presented with an appropriate message when starting your application. Best of all this message is from the OS and thus is localized.

如果您的应用程序无法在运行时从网站下载数据(信号丢失,网站关闭),您应该仍然警告用户,而不是无限期地旋转。

If your application cannot download data from a website while running (loss of signal, site down) you should still warn the user though and not just spin indefinitely.

这篇关于iPhone SDK Internet连接检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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