相关疑难解决方法(0)

NSURLSession:如何增加URL请求的超时?

我使用iOS 7的新NSURLSessionDataTask功能检索数据如下:

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:
request completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
//
}];
Run Code Online (Sandbox Code Playgroud)

如何增加超时值以避免错误"The request timed out"(在 NSURLErrorDomainCode =中-1001)?

我已经检查了NSURLSessionConfiguration的文档,但没有找到设置超时值的方法.

谢谢您的帮助!

http objective-c nsurlconnection ios swift

61
推荐指数
4
解决办法
6万
查看次数

NSMutableURLRequest不服从我的timeoutInterval

我正在发布一个小图片,所以我希望超时间隔很短.如果图像在几秒钟内没有发送,它可能永远不会发送.由于某种未知的原因NSURLConnection,无论我设置多短,我都永远不会失败timeoutInterval.

// Create the URL request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] 
                                 initWithURL:[NSURL URLWithString:@"http://www.tumblr.com/api/write"]
                                 cachePolicy:NSURLRequestUseProtocolCachePolicy
                                 timeoutInterval:0.00000001];

/* Populate the request, this part works fine */

[NSURLConnection connectionWithRequest:request delegate:self];
Run Code Online (Sandbox Code Playgroud)

我有一个断点,- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error但它永远不会被触发.我的图像继续张贴得很好,尽管很小,它们仍然出现在Tumblr上timeoutInterval.

nsurlconnection nsurlrequest nsmutableurlrequest

31
推荐指数
2
解决办法
2万
查看次数