ASIHTTPRequest and background

杀马特。学长 韩版系。学妹 提交于 2019-12-23 01:51:01

问题


Wat happen when we start a request and we enter the background before the request is finished ? Do we have to cancel it ? What is the right way to do so ?

PS : i don't want my download to continue when the user enter background.

Thanks,


回答1:


From the documentation you will see that to continue a request in the background, you need to specifically request that action using;

[request setShouldContinueWhenAppEntersBackground:YES];

The corollary is that if you don't specifically enable it, the download will be cancelled. You should not need to take specific action to do so.

EDIT: Looking at the source, it looks like the download won't explicitly be cancelled by ASIHTTPRequest, but will fail to complete because the operating system is likely to do so for you. If you really want to be sure that it cancelled, perhaps because something nasty happens if you don't, you can always use;

[request cancel];

when you go to the background.

Personally I prefer to be in control of what is going on and would explicitly cancel things I wasn't expecting to finish due to going into the background. It's cleaner and safer because you know 100% what is going on.



来源:https://stackoverflow.com/questions/6913859/asihttprequest-and-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!