I've come across a strange error while programming my iPhone application. Basically when I leave my application in the background and then access it after a long time (i.e. the entire night while I'm sleeping), the viewDidLoad
method seems to be called again even though I did not exit the app (I only double tapped the Home button or I tapped the Home button once) but still left the app in the background. However, if I leave the app on for a short period of time (anytime between a few minutes to a few hours), the viewDidLoad
method is not called again and everything is as it should be. After doing some research, I found that it is because the viewDidUnload
method is called (after the OS finds that the app is suspended for a long time), which calls viewDidLoad
again when we bring the app back up. I found this out through this link: view seems to reload itself but it doesn't seem that there's a way to prevent viewDidLoad
from being called when the viewDidUnload
is called. Is there any way to prevent this viewDidUnload
method from being called again? The thing is I want my app to be running for a long time in the background (i.e. a few days in the background) to collect data. Or, is there no way around this? Any help would be appreciated. Thanks!
我在编写iPhone应用程序时遇到了一个奇怪的错误。基本上当我将我的应用程序留在后台然后在很长一段时间后访问它(即我正在睡觉的整个晚上)时,即使我没有退出应用程序,我也会再次调用viewDidLoad方法(我只是双击主页按钮或我点击主页按钮一次)但仍然在后台留下应用程序。但是,如果我在短时间内(几分钟到几个小时之间的任何时间)启动应用程序,则不会再次调用viewDidLoad方法,一切都应该如此。在做了一些研究后,我发现这是因为调用了viewDidUnload方法(在操作系统发现应用程序被暂停了很长时间之后),当我们重新启动应用程序时再次调用viewDidLoad。我通过这个链接找到了这个:视图似乎重新加载自己,但似乎没有办法阻止在调用viewDidUnload时调用viewDidLoad。有没有办法阻止再次调用viewDidUnload方法?问题是我希望我的应用程序在后台运行很长时间(即在后台几天)来收集数据。或者,有没有办法解决这个问题?任何帮助,将不胜感激。谢谢!
EDIT: I have realized that after iOS 5, viewDidUnload
is deprecated but this phenomenon still occurs. Any ideas on how to fix it? Thanks!
编辑:我已经意识到在iOS 5之后,不推荐使用viewDidUnload,但这种现象仍然存在。关于如何修复它的任何想法?谢谢!
1 个解决方案
#1
0
If you want to do stuff in the background you should look into background tasks.
如果你想在后台做事,你应该研究后台任务。
#1
0
If you want to do stuff in the background you should look into background tasks.
如果你想在后台做事,你应该研究后台任务。