相关疑难解决方法(0)

NSURLConnection超时?

我正在将这个NSURLConnection与代表一起使用.

nsconnection = [[NSURLConnection alloc] initWithRequest:request
    delegate:self startImmediately:YES];
Run Code Online (Sandbox Code Playgroud)

问题是网站根本没有回应.没什么,只是在浏览器中旋转空白页面,没有失败.在我的代表中,我处理失败,但当网站没有响应时,代表不会被调用.有关如何超时连接的任何想法?

iphone timeout nsurlconnection

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

iOS NSURLConnection不从某些URL下载文件

我有NSURLConnection一个tableview单元子类,可以下载大多数文件.但是,我注意到有些人无法开始下载,并且超时.一个例子是这个 URL,它只是一个测试zip文件,可以在任何其他浏览器中正常下载.下载我的代码

-(void)downloadFileAtURL:(NSURL *)url{
    self.downloadedData = [[NSMutableData alloc] init];
    self.url = url;
    conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:self.url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1200.0] delegate:self startImmediately:YES];
}

- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSHTTPURLResponse*)response
{
    int statusCode = [response statusCode];
    if (statusCode == 200){
        self.fileName.text = response.URL.lastPathComponent;
        self.respo = response;
        expectedLength = [response expectedContentLength];
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    [self.downloadedData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
    CFStringRef mimeType = (__bridge CFStringRef)[_respo MIMEType];
    CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType, NULL);
    CFStringRef extension = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension);
    NSString …
Run Code Online (Sandbox Code Playgroud)

objective-c nsurlconnection ios

6
推荐指数
1
解决办法
2321
查看次数

标签 统计

nsurlconnection ×2

ios ×1

iphone ×1

objective-c ×1

timeout ×1