iphone - iOS同步下载过程中的超时间隔?

标签 iphone objective-c ios nsurlconnection nsurlconnectiondelegate

我创建了如下请求,

NSURLResponse *response;
NSError *error;

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:JsonURL];
[request setTimeoutInterval:10];

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

但是这里超时间隔不起作用,我检查了堆栈上的一些问题,有些说默认超时是 75 秒,有些说是 240 秒,我在这里很困惑..

请帮我解决这个问题。

最佳答案

您正在使用同步连接。因此,将不会调用代理。如果您仍然想使用同步 URL 请求,我会推荐以下内容:

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

if (nil == response) {
    if (error)
        NSLog(@"Connection failed! Error - %@ %@",
        [error localizedDescription],
        [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
    }
}

如果您想使用委托(delegate)方法,则必须使用异步请求。

请检查URL Loading System Programming Guide也是。

关于iphone - iOS同步下载过程中的超时间隔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12445066/

相关文章:

ios - 错误: The Info. plist in package must contain the CFBundleIdentifier key

iphone - 删除IOS7导航栏左按钮前的空格?

ios - UIActivityTypeCopyToPasteboard 如何附加图像和文本

ios - Spritekit 从物体前面经过时的剪影效果

html - css 悬停样式和 iOS

iphone - 在 iPhone 3G 上录制视频

ios - 代码中的假平移手势

objective-c - iPhone 6 Plus 在横向模式下自动隐藏状态栏?

ios - 如何将 `CVOpenGLESTextureCacheRef` 转换为 `CVMetalTextureCacheRef` ?

ios - 我如何像引用 IBOutlet 一样在代码中引用 gamescene.sks 中添加的 Sprite ?