草庐IT

sendasynchronousrequest

全部标签

ios - NSURLConnection 和 sendAsynchronousRequest :queue:completionHandler: - does the completion block run in the main thread

如果我将NSURLConnection与sendAsynchronousRequest:queue:completionHandler:一起使用,我是否需要在完成处理程序中采取任何特殊的预防措施?具体来说,通过NSURLConnection直接异步发送是否与使用dispatch_async相同/相似,因为完成block需要返回主线程才能与UI交互?例如:在使用dispatch_async与UI交互(可能是用词不当)后,应用必须使用performSelectorOnMainThread。sendAsynchronousRequest:queue:completionHandler:是否需

ios - 等待直到NSURLConnection sendAsynchronousRequest完成

我有以下问题。我有一个名为User的模型。现在,当用户使用Facebook登录时,我的应用程序会检查该用户是否已存在于数据库中。为了不卡住UI(因为我来自Android),我想使用NSURLConnectionsendAsynchronousRequest。最初起作用的是以下内容:我的用户模型有一种方法可以完成AsynchronousRequest的全部任务,然后在完成后将设置一个变量以进行加载。然后其他类(class),可以简单地检查while(!user.loading)(如果请求已完成)。我遇到的问题是,现在,我不得不在每个模型中都使用此方法。因此,代替此,我创建了一个新的Cla

ios - [NSURLConnection sendAsynchronousRequest : . ..] 总是发送完成 block 吗?

很可能是一个相当微不足道的问题,但是是否总是使用[NSURLConnectionsendAsynchronousRequest:...]调用完成block?或者我是否必须实现超时计时器?考虑以下我在调用之前添加MBProgressView并仅在完成block中删除它的地方:[selfshowHUDWithTitle:@"Configuring"];[NSURLConnectionsendAsynchronousRequest:requestqueue:[[NSOperationQueuealloc]init]completionHandler:^(NSURLResponse*respo

objective-c - sendAsynchronousRequest 与 tableView reloadData 延迟绘制

我正在尝试使用iOS5中添加的新sendAsynchronousRequest。我有一个模型类(File),其方法从服务器请求一些数据,然后将此数据传递给创建模型对象的Controller类(FilesController)。模型类有一个方法,代码如下:[NSURLConnectionsendAsynchronousRequest:requestqueue:[[NSOperationQueuealloc]init]completionHandler:^(NSURLResponse*response,NSData*data,NSError*error){NSArray*decodedRe

ios - NSUrlConnection sendAsynchronousRequest 和自签名证书

我正在编写一些执行http请求的API代码,并且我一直在使用[NSUrlConnection:sendAsynchronousRequest:queue:completionHandler]进行调用,因为它使得编写简单的处理程序变得非常容易,而且我不必为每个调用设置不同的类和不同的委托(delegate)。我遇到的问题是,接受自签名证书的唯一方法似乎是让一个实现几个函数的委托(delegate)说证书没问题。有没有办法用使用block的异步方法来做到这一点? 最佳答案 不,但是委托(delegate)调用并没有那么难。这是您需要的代

ios - sendAsynchronousRequest 说它在展开可选值时发现 nil

这是我的代码崩溃的部分:letbodyData="username="+username+"&password="+passwordletURL:NSURL=NSURL(string:"URLOFAPHPFILE")!letrequest:NSMutableURLRequest=NSMutableURLRequest(URL:URL)request.HTTPMethod="POST"request.HTTPBody=bodyData.dataUsingEncoding(NSUTF8StringEncoding);NSURLConnection.sendAsynchronousReque

ios - NSURLConnection sendAsynchronousRequest 无法从闭包中获取变量

我正在尝试使用POST从PHP页面获取简单的文本响应。我有以下代码:funcpost(url:String,info:String)->String{varURL:NSURL=NSURL(string:url)!varrequest:NSMutableURLRequest=NSMutableURLRequest(URL:URL)varoutput="NothingReturned";request.HTTPMethod="POST";varbodyData=info;request.HTTPBody=bodyData.dataUsingEncoding(NSUTF8StringEnco

swift - 无法使用参数列表在 Swift 2 中调用 'sendAsynchronousRequest'

我目前正在重写部分Swift1.2代码以与Swift2.0兼容。实际上我无法弄清楚对“sendAsynchronousRequest”进行了哪些更改-目前我所有的请求都失败了NSURLConnection.sendAsynchronousRequest(request,queue:queue,completionHandler:{(response:NSURLResponse!,data:NSData!,error:NSError!)->Voidin})Cannotinvoke'sendAsynchronousRequest'withanargumentlistoftype'(NSUR

ios - 使用带有完成处理程序的 NSURLConnection sendAsynchronousRequest 进行身份验证

通常我喜欢使用完成处理程序block使用NSURL的sendAsynchronousRequest类方法“触发并忘记”,但当需要身份验证时,这似乎不是一个选项。当使用这样的完成处理程序样式请求时:[NSURLConnectionsendAsynchronousRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:@"http://www.mysite.com/"]]queue:[NSOperationQueuemainQueue]completionHandler:^(NSURLResponse*response,NSData*

ios - sendAsynchronousRequest 在 iOS 9 中被弃用,如何修改代码来修复

以下是我遇到问题的代码:funcparseFeedForRequest(request:NSURLRequest,callback:(feed:RSSFeed?,error:NSError?)->Void){NSURLConnection.sendAsynchronousRequest(request,queue:NSOperationQueue.mainQueue()){(response,data,error)->Voidinif((error)!=nil){callback(feed:nil,error:error)}else{self.callbackClosure=callb