iPhone:应用程序进入后台时会冻结吗?
我有一个使用 NSUrlConnection 将文件上传到服务器的应用程序。它被放置在 ViewDidLoad 方法上。当应用程序位于前台时,它确实上传到服务器。在异步调用 NSUrlConnection 之前,我在应用程序目录中创建临时文件。
在上传文件时,我单击了 iPhone 按钮,以便应用程序在后台运行。我首先认为应用程序会冻结上传,但事实并非如此。在此期间文件仍在上传。
这是否意味着应用程序仍在后台正常运行,直到剩余时间结束然后应用程序退出?
I have an application that upload file to server using NSUrlConnection. It was placed on ViewDidLoad method. It did upload to server while the application is in foreground. Before I call the NSUrlConnection asynchronously, I create temporary file in application directory.
While the files were uploading, I clicked on the iPhone button so that the application will run in the background. First thing I thought the application freeze the upload, but it doesn't. The file still uploading during that time.
Does that mean the application still running normally at the background until the remaining time finished then the application quits?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦按下主页按钮,每个应用程序都会在后台运行一段时间(通常是几秒钟),然后才会进入挂起模式。如果您需要在进入暂停模式之前完成任务(在您的情况下文件上传),您可以使用 任务完成 API。
即使您是使用任务完成 API,您的应用程序只有一个线程正在运行,而不是整个应用程序。这是苹果推荐的代码:
Once the home button is pressed, every application runs in the background for a certain amount of time(usually few seconds) before it enters suspended mode. If you are required to complete a task(in your case file upload) before entering suspended mode, you can use Task completion API.
Even if you are using task completion API, only one thread of your application is running, but not the whole application. Here is the code recommended by apple: