Tag: nsurlconnectiondelegate

asynchronousNSURLConnection和保持活动

我正在使用NSURLConnectionasynchronous地执行一系列的HTTP请求到同一个主机,即[initWithRequest:delegate:startImmediately:]和一个委托。 当connectionDidFinishLoading通知来到委托,我释放我的连接对象,然后初始化并启动另一个,到同一主机。 问题 – 底层套接字是否会被重用? Connection:keep-alive服务器头在那里,但我没有办法确保它被尊重。 我的意思是,第一个连接在发布通知时还没有正式“完成”。 还是呢? 编辑: 数据包在Mac上嗅探 。 PacketLogger随附硬件工具。 编辑2:看起来像它不捕获iOS模拟器的活动。

NSURLConnection didSendBodyData进度

我正在使用POST请求上传一些数据到服务器,我试图根据NSURLConnection的didSendBodyData方法的totalBytesWritten属性更新UIProgressView的进度。 使用下面的代码,我没有得到适当的进度视图更新,它始终为0.000,直到完成。 我不确定要乘以或除以获得更好的上传进度。 我会很感激提供的任何帮助! 码: – (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite { NSNumber *progress = [NSNumber numberWithFloat:(totalBytesWritten / totalBytesExpectedToWrite)]; NSLog(@"Proggy: %f",progress.floatValue); self.uploadProgressView.progress = progress.floatValue; }

将总是发送完成块?

最有可能是一个相当微不足道的问题,但完成块将始终使用[NSURLConnection sendAsynchronousRequest: …]来调用? 或者我必须实现一个超时定时器? 请考虑以下情况,在调用之前添加MBProgressView ,并仅在完成块中将其删除: [self showHUDWithTitle:@"Configuring"]; [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { if ([data length] >0 && error == nil) { [self hideHUDWithFlag:YES andTitle:@"Finished" andSubtitle:@"(Box was configured)"]; } else if ([data length] == 0 && error == nil) { [self hideHUDWithFlag:NO andTitle:@"Failed" andSubtitle:@"(Check box connection)"]; NSLog(@"Nothing was […]

该服务器的证书无效

我知道,如果我使用以下nsurlconnectiondelegate它将被修复 – 连接:willSendRequestForAuthenticationChallenge: – 连接:canAuthenticateAgainstProtectionSpace 但我正在尝试使用 sendAsynchronousRequest:队列:completionHandler: 所以你没有得到callback。 我看着它跟随的苹果文档 如果需要进行身份validation才能下载请求,则必须将所需凭据指定为URL的一部分。 如果身份validation失败,或者凭据丢失,则连接将尝试继续而没有凭据。 我无法弄清楚如何做到这一点。 当我抬起头时,我所得到的就是这个私人电话 +(void)setAllowsAnyHTTPSCertificate:(BOOL)inAllow forHost:(NSString *)inHost; 任何想法如何做到这一点? 以下是我得到的错误 该服务器的证书无效。 您可能正在连接到假装为“example.com = 0x8b34da0 {NSErrorFailingURLStringKey = https://example.com/test/,NSLocalizedRecoverySuggestion =您要连接到服务器?NSErrorFailingURLKey = https:/ /example.com/test/,NSLocalizedDescription =此服务器的证书无效。 你可能会连接到一个伪装成“example.com”的服务器,这个服务器可能会把你的机密信息置于危险之中,NSUnderlyingError = 0xa26c1c0“这个服务器的证书是无效的,你可能连接到假装成为“example.com”这可能会把你的机密信息置于危险之中。“,NSURLErrorFailingURLPeerTrustErrorKey =

NSURLConnectionDownloadDelegate文件问题

现在5.0版本已经推出了,我们可以在不违反苹果的NDA的情况下讨论它,但是对于新版本的NSURLConnection我有一个问题。 这有一个新的委托NSURLConnectionDownloadDelegate与两个关键的方法。 connection:didWriteData:totalBytesWritten:expectedTotalBytes:在文件下载正在进行时重复调用 connectionDidFinishDownloading:destinationURL:在下载完成时调用一次。 下载的文件应该在destinationURL(至less在这个方法的生命周期中 – 意图是你得到它并将它移到永久的地方)。 问题是:它不在那里。 那个目录是空的。 我已经把这个漏洞报告给了苹果公司,他们告诉我这是一个他们已经意识到的问题的重复。 如果任何人有解决方法,或者发现他们可以成功使用这个委托,请让我知道。 UPDATE 10/17/2011:我已经放弃了这一点,并返回到旧的委托,仍然在5.0工作正常,即使文档说委托方法只能通过4.3。

iOS4的实现 – ?

我怎么能实现-[NSURLConnection sendAsynchronousRequest:queue:completionHandler:] iOS的-[NSURLConnection sendAsynchronousRequest:queue:completionHandler:] <5? #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0 #import <objc/runtime.h> #import "NSURLConnection+iOS4.h" // Dynamically add -[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]. void *sendAsynchronousRequest4(id self, SEL _cmd, NSURLRequest *request, NSOperationQueue *queue, void (^handler)(NSURLResponse*, NSData*, NSError*)); void *sendAsynchronousRequest4(id self, SEL _cmd, NSURLRequest *request, NSOperationQueue *queue, void (^handler)(NSURLResponse*, NSData*, NSError*)) { // How should we implement this? } @implementation NSURLConnection (SendAsync) […]

如何unit testing一个NSURLConnection委托?

我怎样才能unit testing我的NSURLConnection委托? 我做了一个ConnectionDelegate类,它符合不同的协议,以便将来自Web的数据提供给不同的ViewController。 在我太远之前,我想开始写我的unit testing。 但是我不知道如何testing他们作为一个单位没有互联网连接。 我也想我应该做什么来处理asynchronouscallback。

iphone:安全restfull服务器“此服务器的证书无效

我正在尝试使用安全的宁静的服务,这给了错误 错误=错误域= NSURLErrorDomain代码= -1202“此服务器的证书无效,您可能正在连接假装为”xxx.xxx.xxx.xxx“的服务器,这可能会将您的机密信息置于危险之中。 在xCode 4.2上工作,在哪里错误或缺less任何步骤。 使用下面的代码 RegisterUser.f @interface RegisterUser : UIViewController<UITextFieldDelegate, UIScrollViewDelegate, NSURLConnectionDelegate> RegisterUser.m – (IBAction)SubmitBtnAction:(id)sender { NSURL *url = [NSURL URLWithString:@"https://xx.xx.xx.xxx:8223/jaxrs/tunedoorgateway/getCountries"]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; [NSURLConnection sendAsynchronousRequest:urlRequest queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { if ([data length] >0 && error == nil) { NSLog(@"Data = %@", data); // DO […]