sendSynchronousRequest

sendSynchronousRequest

本文介绍了使用 NSURLConnection sendSynchronousRequest 处理错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

如何使用 NSURLConnection sendSynchronousRequest 更好地处理错误?有什么办法可以实现

how can i do better error handling with NSURLConnection sendSynchronousRequest? is there any way i can implement

- (void)connection:(NSURLConnection *)aConn didFailWithError:(NSError *)error

我有一个 nsoperation 队列,它在后台获取数据,这就是我有同步请求的原因.如果我必须实现异步请求,那么我如何等待请求完成.因为没有数据,该方法无法继续.

i have a nsoperation queue which is getting data in background thats why i have sync request.and if i have to implement async request then how can i wait for request to get complete. because that method can't proceed without data.

推荐答案

-sendSynchronousRequest:returningResponse:error: 为您提供了一种直接在方法本身中获取错误的方法.最后一个参数确实是 (NSError **) 错误;也就是说,一个指向 NSError 指针的指针.试试这个:

-sendSynchronousRequest:returningResponse:error: gives you a way to get an error right there in the method itself. That last argument is really (NSError **) error; that is, a pointer to an NSError pointer. Try this:

NSError        *error = nil;
NSURLResponse  *response = nil;

[NSURLConnection sendSynchronousRequest: req returningResponse: &response error: &error];

if (error) {...handle the error}

这篇关于使用 NSURLConnection sendSynchronousRequest 处理错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 00:05