iOS 7后台上传和POST请求 [英] iOS 7 background upload and POST requests

查看:151
本文介绍了iOS 7后台上传和POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在每次上传之前和之后用其他HTTP POST 请求在后台上传文件。

以前我使用 beginBackgroundTaskWithExpirationHandler 这是完美的工作,直到iOS 6,但从IOS 7只限于约180秒,这是一个问题。



我已阅读文档关于NSURLSession在我们有后台传输服务。但是这个问题只允许在后台上传和下载。它不允许我在每次上传后在后台发出POST请求。



那么有什么办法可以让POST请求和后台上传一起吗?
$ b

任何提示正确的方向将是高度赞赏。

解决方案我认为你可以使用NSURLSessionDownloadTask来发送POST。



IMO,下载任务并不意味着它被用于下载。这意味着您的POST请求(json / xml)的响应将被下载到本地文件。然后你可以打开这个文件并解析它来获得请求。

如果你想要的话你甚至可以使用NSURLSessionDownloadTask来上传文件到S3。而s3响应将被下载到本地文件中。



有关更多信息,请参阅Apple开发人员论坛中的此问题https://devforums.apple.com/thread/210515?tstart=0


I need to upload files in the background with other HTTP POST requests before and after each upload.

Previously I was using beginBackgroundTaskWithExpirationHandler which was working perfectly till iOS 6 but from IOS 7 it is restricted for approx 180 seconds only which is a concern.

I have read the documents regarding NSURLSession were in we have Background transfer service. But the problem with this is it only allows upload and download in background. It doesn't allow me to make POST request after every upload in the background.

So is there any way to make the POST request along with the background uploads?

Any hint in the right direction would be highly appreciated.

解决方案

I think you can use NSURLSessionDownloadTask to send a POST.

IMO, download task doesn't mean it is used for download. it means the response of your POST request (json/xml) will be downloaded to a local file. Then you can open that file and parse it to get the request.

if you want you can even use a NSURLSessionDownloadTask to upload files to S3. and the s3 response will be 'downloaded' to a local file..

for more information, see this question in the apple developer forum https://devforums.apple.com/thread/210515?tstart=0

这篇关于iOS 7后台上传和POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆