ios - 解析错误的 UI

标签 ios swift parse-platform

我想在每次生成解析请求并失败时向用户添加通知(AlertView)。例如,告诉用户网络连接已关闭或他们尝试的用户名已被占用。是否可以在一个地方(如设置或子类)添加 UI 来收集和显示所有错误消息?我希望不必处理每个 PFQuery 中每个 if error != nil block 中的每种可能的错误。

我知道有些错误是独特的,必须单独处理,但同时其他错误是通用的,例如网络和登录/注册,并且应该有预设的用户警报。我知道 Parse 已经通过打印网络错误在某种程度上做到了这一点,我只是想知道是否有一种方法可以简单地捕获这些打印输出的创建位置并从那里提醒用户。我正在讨论的网络错误的一个示例是:

2015-10-27 22:00:47.501 YLSA[39956:2216153] [Error]: The Internet connection appears to be offline. (Code: 100, Version: 1.9.1)
2015-10-27 22:00:47.501 YLSA[39956:2216153] [Error]: Network connection failed. Making attempt 1 after sleeping for 1.024460 seconds.
2015-10-27 22:00:47.502 YLSA[39956:2216153] [Error]: The Internet connection appears to be offline. (Code: 100, Version: 1.9.1)
2015-10-27 22:00:47.502 YLSA[39956:2216153] [Error]: Network connection failed. Making attempt 1 after sleeping for 1.934890 seconds.
2015-10-27 22:00:47.502 YLSA[39956:2216153] [Error]: The Internet connection appears to be offline. (Code: 100, Version: 1.9.1)
2015-10-27 22:00:47.502 YLSA[39956:2216153] [Error]: Network connection failed. Making attempt 1 after sleeping for 1.236957 seconds.
2015-10-27 22:00:48.571 YLSA[39956:2216153] [Error]: The Internet connection appears to be offline. (Code: 100, Version: 1.9.1)
2015-10-27 22:00:48.571 YLSA[39956:2216153] [Error]: Network connection failed. Making attempt 2 after sleeping for 2.048920 seconds.
2015-10-27 22:00:48.742 YLSA[39956:2216153] [Error]: The Internet connection appears to be offline. (Code: 100, Version: 1.9.1)
2015-10-27 22:00:48.742 YLSA[39956:2216153] [Error]: Network connection failed. Making attempt 2 after sleeping for 2.473915 seconds.
2015-10-27 22:00:49.440 YLSA[39956:2216148] [Error]: The Internet connection appears to be offline. (Code: 100, Version: 1.9.1)
2015-10-27 22:00:49.440 YLSA[39956:2216148] [Error]: Network connection failed. Making attempt 2 after sleeping for 3.869780 seconds.

谢谢

最佳答案

大多数事情都是在 View Controller 中开始和结束的。确保 vc 中调用解析方法的方法具有包含结果和 NSError 的 block 参数。

您的 View Controller 可能已经继承自应用程序级 vc,该 vc 集中了有关外观和行为的一些详细信息。这是添加通用错误处理的好地方。

所以应用程序的 View Controller :

* change the UI to indicate "busy" state
* start a chain of calls that lead to server calls
* results and NSErrors are passed back up the chain 
* in the vc, in the completion blocks:
   - change the UI to indicate not "busy"
   - handle errors for things that are custom to the call
   - call the inherited handler for errors that are handled generically

关于ios - 解析错误的 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33381575/

相关文章:

ios - 如何在iOS Phonegap应用中压缩WAV文件

ios - 在 Swift 上捕获错误并将其显示在 View Controller 上并发出警报

iOS:如何在 WKWebView 中加载本地文件(不在 bundle 中)?

swift - 在闭包中返回泛型类型的动态泛型参数?

ios - AppDelegate 中的 UITextField 自定义不适用于 Swift

ios - 没有互联网连接时显示聊天数据,如 WhatsApp

java - Android Fragment 在第二次单击选项卡之前不会加载数据

ios - 设置自定义开关

node.js - 在一个 Node.js 环境中运行多个 Parse 服务器实例

ios - 从类中获取变量数据 - swift