开发中不可避免的会和网络请求打交道,那如何正确处理网络回调呢?
- Verify that the error parameter is nil. If not, a transport error has occurred; handle the error and exit.
验证error参数是否为空,如果不为空,表明网络传输发生错误,捕获并处理。 - 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参数,并验证返回码和返回值类型是否如你所愿,如果不是,捕获并处理这个服务器错误。 - Use the data instance as needed.
拿到数据,做业务处理。