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 - 使用 dequeueReusableCell 重写单元格

ios - 未设置 Firebase iOS SDK + GTM + Analytics 类别

ios - Swift AppDelegate 在 ViewController 之间传递数据

java - 从解析表中检索字符串值

parse-platform - 解析 Javascript SDK 查询 : Combining two queries using AND

ios - react native : how to put element to the right in parent view

ios - PushKit Xcode 9.2 问题 : Not able to get device token

swift - 使用索引(:) on Array of Protocol Type in Swift

ios - 如何将新卡/来源添加到 Stripe 客户帐户?

ios - 在 iOS 中设置 Parse