美文网首页
iOS 网络回调的正确处理方式

iOS 网络回调的正确处理方式

作者: 王小宾 | 来源:发表于2018-08-13 17:04 被阅读62次

开发中不可避免的会和网络请求打交道,那如何正确处理网络回调呢?

  1. Verify that the error parameter is nil. If not, a transport error has occurred; handle the error and exit.
    验证error参数是否为空,如果不为空,表明网络传输发生错误,捕获并处理。
  2. Check the response parameter to verify that the status code indicates success and that the MIME type is an expected value. If not, handle the server error and exit.
    查看response参数,并验证返回码和返回值类型是否如你所愿,如果不是,捕获并处理这个服务器错误。
  3. Use the data instance as needed.
    拿到数据,做业务处理。

相关文章

网友评论

      本文标题:iOS 网络回调的正确处理方式

      本文链接:https://www.haomeiwen.com/subject/pwmubftx.html