gpt4 book ai didi

ios - 解析错误的 UI

转载 作者:行者123 更新时间:2023-11-30 13:57:50 25 4
gpt4 key购买 nike

我想在每次生成解析请求并失败时向用户添加通知(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com