最佳做法-没有网络连接 [英] Best practice - No network connectivity

查看:48
本文介绍了最佳做法-没有网络连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您认为什么是处理无网络连接的最佳方法?

What do you think would be the best way to handle no network connectivity?

我未来的应用程序在很大程度上依赖于网络,没有它,它将与它无关.

My future app heavily relies on network and without it there will be nothing to do with it.

我看到应用程序以不同方式处理这种情况.

I see apps handling the situation in different ways.

例如,当我没有连接时,ebay应用有时会提取最近保存的数据,而在另一些时候,它会清除所有内容.贝宝(Paypal)应用程序将注销我,否则它将崩溃.其中一个新闻应用程序只会说说正在加载...

When I don't have connection the ebay app for example sometimes pulls the last saved data, but some other time it just clears everything out. Paypal app will either log me out or it will just crash. One of the news app will just keep say loading...

那里有最佳实践吗?

应用程序应继续尝试并显示加载消息,添加刷新按钮还是仅自动关闭应用程序?

Should the app keep trying and display loading message, add a refresh button or just close the app automatically?

谢谢

推荐答案

无网络"条件的正确处理方式完全取决于您的应用程序.

What the proper handling of "no network" condition is, entirely depends on your application.

需要牢记的两件事:以编程方式关闭应用程序或无法顺利处理无连接"的情况,都是在Apple审核过程中被拒绝的原因.

Two things to keep in mind: programmatically closing an app or not handling smoothly the "no connection available" case are both reasons for rejection in the Apple review process.

曾经在设计过一个很大程度上依赖于网络可用性的应用程序方面有经验,我想说,最佳实践可以总结如下:

Having had experience with designing an app that also heavily depended on network being available, I would say that best practice can be summarized in the following:

1)使用 Reachability 框架进行检测您拥有什么样的连接;我链接到的版本优先于Apple提供的版本,该版本有很多错误(有关更多信息,请搜索S.O);

1) use the Reachability framework to detect what kind of connectivity you have; the version I link to is to be preferred to the one provided by Apple, which is buggy (search S.O for more on this);

2)每次需要从网络获取数据时,请检查是否恢复了连接(即,刚开始时不止一次);

2) each time you need data from the network, check whether connection is back (i.e., not just once at the beginning);

3)始终通过显示警报或更好地显示其他种类的图标/消息的方式通知用户没有可用的网络;最少干扰的显示是最好的,以免干扰用户的工作流程;

3) always inform the user that no network is available, when this occurs, either by displaying an alert, or better showing some other kind of icon/messaging; the least intrusive kind of display is best, so to not disrupt the user's workflow;

4)如果您已经缓存了数据并且这样做是有道理的,请在没有网络连接可用时使用缓存的数据(在这种情况下,这也会使该应用程序部分可用");

4) if you have cached data and this makes sense, use cached data when no network connection is available (this will make the app "partially usable" in such cases as well);

5)为用户提供刷新数据的按钮,如果这对您的应用有意义;

5) offer the user a button to refresh the data, if this make sense for your app;

这就是说,最佳做法"的最简单实现是一个应用程序,如果没有可用的连接,则会使用户回到主屏幕"(丑陋,但这可能是您应用程序中唯一明智的选择).完全实现是,例如,一个rss阅读器将所有新闻缓存起来,即使没有连接也可以使您阅读它们(显然不加载新数据).

This said, the simplest implementation of this "best practice" is an app that in case no connection is available, gets the user back to the "main screen" (ugly, but it could be the only sensible thing in your app). Full implementation is, say, an rss reader caching all the news and allowing you to read them even when no connection is there (without loading newer data, obviously).

这篇关于最佳做法-没有网络连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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