问题标签 [nsurlsessiondatatask]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ios - 将 NSURLConnection+delegate 替换为 NSURLSession+delegate?
首先有很多类似的问题,但它们都是关于NSURLSessionDataTask
使用完成处理程序创建的。就我而言,我有NSURLConnection
很多委托方法,我需要将其替换为NSURLSession
.
根据此链接,我需要委托方法URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:
,但我不明白如何使用它,因为所有示例都是关于使用完成处理程序(只是成功或失败)创建任务,根本没有使用委托。
ios - Using nsurlsessiontask causing data in table view to be showed incorrectly and change will scrolling
I am using the google places api to get details about stores near the user. The response I get from the call, I display in a table view. I make two api calls. One call to find nearby stores, and another call to get information about each returned store such as url, phone number, picture etc. So I first made both these calls on the main thread and it slowed down my UI. The table view lagged a lot while scrolling (but all the cells had correct data and when scrolling up or down the data did not change). Then I decided to use nsurlsessiontask to perform both the api calls so it would not slow down the UI. Here is code:
First api call:
So basically I created and initialized the jsonDict which the the dictionary that holds the data. Now in my class that shows the tableview, I take the data from jsonDict and display it in the cell. For example:
In order to get the phone number and website of the store I need to make another http request. So I make a a method in the same class that displays the tableView. Here is the code:
So when I do this the table view does not "lag" however the data shown is incorrect(cells show data of other cells) and when I scroll up or down the data changes? So when I perform task on main thread there is lag but correct data is displayed, when I use nsurlsessiontask there is no lag but the data shown is incorrect. I am doing anything wrong with the nsurlsessiontask?
ios - NSOperationQueue 或 NSURLSession 同步获取数据
在我的应用程序中,当我们点击登录按钮时,我们必须进行 3 次服务器调用。
我对为此采取的方法感到困惑。使用 operationqueue 添加依赖项或使用 NSURLSession 任务是一个好方法吗?
根据对此的堆栈溢出解决方案之一-制作 NSURLSessionTasks 队列的最佳实践, NSURLSession 没有任何关于排序请求的逻辑,即使将每个主机的最大连接数设置为1
如果有任何其他更好的方法让我知道..
ios - 当应用程序未激活或屏幕关闭时如何恢复下载
我想从服务器下载一个文件,它大约 30/MB。
NSURLSessionDataTask
是我用于下载的功能。我想知道如何在应用程序进入background state
或屏幕关闭时实现下载文件。
swift - 如何在 swift 2 中在 http POST 请求中添加参数(用于 Drupal7 评级字段)
我是一个初学者,尝试编写代码以向具有电影内容的节点的 Drupal7 评级字段提交投票。正如节点有一个“title”参数一样,有一个“rating-percent”参数,其格式为“75%”。来自节点视图的 json 输出的 GET 请求会像这样获取评分百分比(连同许多其他字段)。
我要在此代码中添加什么以将数据值(例如 75%)发布到“rating-percent”参数?这是我在 POST 上的尝试:
非常感谢您提供的任何帮助。
ios - iOS:发出多个 NSURLSession 请求
我需要发出多个 http 请求,但我需要等待请求的响应才能继续下一个,但我不知道该怎么做。有没有人知道我怎么能不使用 dispatch_semaphore 做到这一点
这是我的代码:
我会非常感谢你的帮助。
ios - 添加配置时Swift 2 nil NSURLSessionDataTask
当session
设置.init(configuration:..., delegate:self, delegateQueue:NSOperationQueue.mainQueue())
为代理服务器重定向时,NSURLSessionDataTask.resume()
不会导致执行task
. 当session
设置为.sharedSession()
时,task
按预期执行。
**kCFStreamPropertyHTTPProxyHost
等已被弃用。也许这会NSURLSessionConfiguration
以一种阻止执行的方式影响task
?
swift2 - Swift 2 如何在继续之前强制会话数据任务执行 .resume()
我会疯狂地试图弄清楚如何在会话 dataTaskWithRequest 完成之前阻止我的其余代码执行。无论我做什么,数据任务都不会 .resume() 直到其他一切都完成。没有任何效果。不使用 while 循环。不将任务放在单独的线程中(dispatch_async)。我无计可施。更糟糕的是,我觉得我忽略了一些简单的事情,因为似乎没有其他人在问这个问题。
ios - NSURLSession,数据任务转换为下载任务后,后台无法下载
如果我运行以下代码并让应用程序在后台运行,下载仍在继续。最后,当下载完成时,我可以得到正确的回调。
但是我有一个要求,就是我要判断服务器返回给我的是什么,如果是json,我不做下载,所以我想先获取响应头,然后如果需要下载,我将数据任务更改为下载任务,所以我按照以下代码进行
然后我可以在回调中获取响应头,如果需要下载文件,我可以将数据任务更改为下载任务,如下
到目前为止,一切都很好。当我在前台运行应用程序时,效果和我想的一样。但是应用程序在后台运行后,下载停止,然后当我打开应用程序时,控制台显示“与后台传输服务的连接丢失”。
原以为苹果很聪明,他给了我们很多有用的回调,但是现在,我不知道我哪里错了,我也看到了关于 AFNetworking 和 Alamofire 的源代码,但是我没有找到引用的东西。
我也认为这是一个普遍的要求,但我在互联网上找不到任何有用的信息,这太奇怪了。
所以希望你能帮助我,谢谢十亿。
ios - 什么时候使用 NSURLSessionDownloadTask 和 NSURLSessionDataTask?
这两者有什么区别。我可以使用两者从服务器获取数据。