Tag: nsurlconnection

处理多个NSURL连接的最佳方法

我正在尝试以编程方式创build一个xls表单。 为了填写表格,我使用了100多个NSURLConnection 。现在,我的方法是: build立连接并将数据存储到数组中。 这个数组有100个对象。 现在取第一个对象并调用连接。 存储数据。 并使第二个对象在数组中的第二个连接。 这一直持续到数组中的最后一个对象。 平均需要14秒才能完成100个连接。 有什么办法来实现NSURLConnection以更快的方式获得响应? 直到昨天我遵循的基本方法,如: 声明属性: @property (nonatomic,strong) NSURLConnection *getReportConnection; @property (retain, nonatomic) NSMutableData *receivedData; @property (nonatomic,strong) NSMutableArray *reportArray; 在viewDidLoad初始化数组: reportArray=[[NSMutableArray alloc]init]; 在button操作中初始化NSURLConnection : /initialize url that is going to be fetched. NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"****/%@/crash_reasons",ID]]; //initialize a request from url NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; […]

错误:__tcp_connection_write_eof_block_invoke写closurescallback收到错误 – iOS 10

发送XML基本API请求到ONVIF摄像头。 它在ios 9设备上运行正常,但在iOS 10上出现“500内部错误”。 XCode 8控制台打印下面的错误消息: 2016-09-30 12:39:51.295419 VCPlugin[278:10183] [] nw_socket_get_input_frames recvmsg(fd 12, 1024 bytes): [54] Connection reset by peer 2016-09-30 12:39:51.301221 VCPlugin[278:10228] [] nw_socket_write_close shutdown(12, SHUT_WR): [57] Socket is not connected 2016-09-30 12:39:51.301307 VCPlugin[278:10228] [] nw_endpoint_flow_service_writes [3 10.107.2.153:80 ready socket-flow (satisfied)] Write request has 0 frame count, 0 byte count 2016-09-30 12:39:51.301903 VCPlugin[278:10185] [] […]

在asynchronousHTTP请求的completionHandler中更新视图时延迟

在我的应用程序中,当用户按下一个button时,我开始一个HTTPasynchronous请求(使用[NSURLConnection sendAsynchronousRequest…] ),并在completionHandler块中更改UILabel的文本。 然而,这一变化在请求结束时不会发生,而是在2-3秒后发生。 下面是导致这种行为的代码片段。 – (IBAction)requestStuff:(id)sender { NSURL *url = [NSURL URLWithString:@"http://stackoverflow.com/"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler: ^(NSURLResponse *response, NSData *data, NSError *error) { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; exampleLabel.text = [NSString stringWithFormat:@"%d", httpResponse.statusCode]; }]; } 当我尝试在completionHandler创build一个UIAlertView时,会发生类似的行为。 – (IBAction)requestStuff:(id)sender { NSURL *url = […]

NSMutableArray内的块泄漏(ARC)

我有一些块内的操作。 这个操作只是像这样更新一个UIImage : ^(UIImage *image) { self.myImage = image; }]; 我的图像是通过NSURLConnection访问互联网来计算的。 当我从互联网上收到图像时,我会调用NSMutableArray那个块。 到现在为止还挺好。 我的问题是,当我有多个图像具有相同的URL,而不是进行多个调用,我只是添加一个新的块到处理连接的类内的NSMutableArray 。 这样,我只需要打一个电话,就可以更新多个共享URL的图像。 一切正常,问题是,我正在泄漏块。 我将这样的块添加到NSMutableArray : if( (self = [super init]) ) { self.connectionURL=url; self.arrayOfBlocks=[NSMutableArray array]; [arrayOfBlocks addObject:completion]; } return self; 这是连接类被初始化的时候。 这是当我需要添加一个新的块到NSMutableArray (我只添加它,就是这样): [arrayOfBlocks addObject:completion]; 这是当我最终收到回电,并开始执行块: for (MyBlock blockToExecute in arrayOfBlocks) { blockToExecute([UIImage imageWithData:data]); } 问题是这个漏水了。 因为我在ARC环境中,所以无法抵消使用版本或自动发布的情况。 那么有什么解决办法?

何时调用NSURLConnection委托释放?

将委托传递给NSUrlConnection对象时,如下所示: [[NSURLConnection alloc] initWithRequest:request delegate:handler]; 什么时候你应该在委托上发布发布? 应该在connectionDidFinishLoading ? 如果是这样,我不断得到exec_bad_access 。 我看到我的代表正在通过仪器泄漏。 谢谢

阅读NSURLresponse

我发送一个对象到这个意见: https://sandbox.itunes.apple.com/verifyReceipt ://sandbox.itunes.apple.com/verifyReceipt 与NSUrlconnection ,我想用这个委托方法读取它: – (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response如下: NSlog(@"%@",response); 我得到这个代码: <NSHTTPURLResponse: 0x7d2c6c0>我需要得到一个string莫名其妙。 我怎么读?

在iOS Swift中执行POST请求

我正在尝试执行POST请求,请求不通过。 我已经通过在Swift执行POST请求,但它不包含我在找什么。 func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool { var request = NSMutableURLRequest(URL: NSURL(string: "https://us1.lacunaexpanse.com")) println("request url https://us1.lacunaexpanse.com") var session = NSURLSession.sharedSession() request.HTTPMethod = "POST" let apikey = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" println("apikey",apikey) let username = "username" let password = "password" var login = Array(["username", "password", "apikey"]) let jsonDictionary = ["2.0", "jsonrpc", "1", "id", "login", "method", […]

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) […]

在iOS7 GM中收到SSL错误 – “AddTrust External CA Root”不受信任?

我在NSURLConnection类中突然从iOS7 GM收到SSL错误。 我无法访问我的任何API或WebView页面,并且是严重的紧急情况。 有人可以帮我吗? 错误如下: NSURLConnection / CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813) 我查了一下错误,解释如下: errSSLNoRootCert = -9813,/ *证书链不通过根validation* / 我的域根证书(通过浏览器访问确认)是 “AddTrust External CA Root” 。 这是不太可信的,因为: 此根证书甚至列在“iOS5和6:受信任的根证书列表”中。 http://support.apple.com/kb/ht5012 这个错误从来没有出现过,直到iOS6,甚至直到iOS7 beta6。它突然出现在iOS7 GM。 我的浏览器告诉我这是一个可信的证书。 我的证书的到期date没有问题。 我想知道这是否是操作系统中的错误,或者是否需要购买不同根的证书,或者是否存在其他问题。 PS我没有代码在我的NSURLConnection处理身份validation的挑战。

锁屏中断NSURLConnection

当用户locking和解锁iPad屏幕时,我想知道幕后发生了什么。 我有一个应用程序,使用NSURLConnection下载文件和下载失败与SOAP错误(“具有指定主机名的服务器无法find”),但不是当用户locking屏幕,但当它解锁它。 不pipepopup错误的时候,下载都不会结束。 任何想法为什么和可以做些什么呢? NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:300]; NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest: request delegate: self]; 从我可以告诉的是,当我点击主页button,我得到: applicationWillResignActive applicationDidEnterBackground 在三分钟后我回想起应用程序后,我得到: applicationWillEnterForeground 并且下载或者已经完成或者甚至在后台进行。 当我在后台更长的时间(5分钟),它超时出错。 当我locking屏幕时,我得到相同的应用程序状态的顺序,但也是关于下载断开的错误消息。 谢谢!