NSURLSessions后台会话的正确用例是什么? [英] What is the proper use case for NSURLSessions background sessions?

查看:125
本文介绍了NSURLSessions后台会话的正确用例是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的评论中,我正在讨论有关backgroundTasks的讨论,最终导致了:

In the comments of this answer I was having a discussion about backgroundTasks which eventually led to:

将backgroundTasks用于与下载/上传无关的任何事情.对于上传/下载,请使用NSURLSessions的backgroundSessions.然后,我又发表了一条评论,询问为什么不对所有类型的请求使用后台会话,并被告知:

Use backgroundTasks for anything that isn't related to download/upload. For upload/download use NSURLSessions's backgroundSessions. Then I made another comment asking why not use background Sessions for all types of requests and was told:

对于常规的REST调用,后台会话不太方便, 通常不是您想要的.它们不是通用工具 对于每个请求;它们用于执行上传和下载.

For regular REST calls, background sessions are much less convenient, and generally not what you'd want. They're not a general purpose tool for every request; they're for performing uploads and downloads.

是什么使后台会话不太方便进行REST调用?有时您的互联网速度可能很慢,但其中包含大量数据.确保所有数据提交都通过方便吗?

What makes background sessions less convenient for REST calls? Sometimes you may have slow internet with a huge chunk of data. Wouldn't it be a convenience to make sure all your data submissions go through?

推荐答案

我不确定,但是如果您要进行银行交易之类的操作,则不希望使用backgroundSession.因为您希望用户在离开之前就知道该决定.用户永远不要以为自己可以离开应用程序,并且应用程序将继续正常运行.他们也不应该对他们可以恢复(通过downloadTaskWithUrl)印象深刻.

I'm not sure but if you're doing something like a bank transaction, you wouldn't want to use a backgroundSession. Because you want the user to know of the decision before they leave. User should never the assumption that they could leave app and app would continue to work as should. Nor they should be under the impression that they can resume (by a downloadTaskWithUrl).

如果用户出于某种原因进行了$ 2000交易并按下期望按钮进行交易,但没有,将会发生什么.下次用户返回到屏幕时,他们可能由于安全原因而注销,却一无所知,或者保持登录状态,但是他们看到有关事务失败的警报.现在,他们就像哦,我女儿没有急需的2000美元.她一定还在等钱!".

What happens if for some reason the user makes a $2000 transaction and hits the button expecting the transaction to go through but it doesn't. The next time the user comes back to the screen they could either be logged out due to security reasons and never know about it or stay logged in but they see an alert that the transaction failed. And now they're like "Oh no my daughter needed $2000 urgently. She must be still waiting for the money!".

您不想让用户有不良期望*.相反,您希望用户自己承担全部责任,而不是进入主屏幕并等待成功/失败.因此,一旦用户单击提交传输,他将等待它获得成功并继续前进,或者看到失败并等待并调查其交易未通过的原因.

You don't want to allow users to have bad expectations*. Rather you want users to take FULL responsibility themselves and not hit home screen and wait for the success/failure. So once the user clicks on submit transfer he'd wait for it to either get success and move on or see failure and wait and investigate the reason his transaction didn't go through.

您通常通过微调器/动画传达失败的可能性,并通过警报传达实际结果(失败或成功).

You usually convey the possibility of failure through an spinner/animation and the actual outcome (failure or success) through an alert.

*糟糕的期望是:每次我按下提交传输"按钮时,它都会通过,失败的机会为0,不需要您等待它通过.

*Bad expectation is: Every time I hit the the submit transfer button it will go through and there's 0 chance of failure and no need for you to wait and see it go through.

这篇关于NSURLSessions后台会话的正确用例是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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