每次生成Parse请求并失败时,我都想向用户添加通知(AlertView)。例如,告诉用户网络连接已关闭或已经尝试了他们尝试过的用户名。是否可以在一个地方(如设置或子类)添加UI来收集和显示所有错误消息?我希望不必在每个if error != nil
中的每个PFQuery
块中处理每种类型的可能错误。
我知道有些错误是独一无二的,必须单独处理,但同时其他错误也是通用的,例如网络和登录/注册,并且应该有固定的用户警报。我知道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.
由于
答案 0 :(得分:0)
大多数东西在视图控制器中开始和结束。确保vc中调用解析方法的方法具有包含结果和NSError的块参数。
您的视图控制器可能已经从应用级vc继承,该vc集中了一些有关外观和行为的详细信息。这是添加常规错误处理的好地方。
所以app的视图控制器:
* 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