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

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

  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.
    拿到数据,做业务处理。
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容