Difference between “terminating” an app , opening the “task switcher” and “auto lock”

旧时模样 提交于 2019-12-25 16:48:11

问题


I'm aware of the fact that the title of this thread is substandard. Anyhow, here's the issue I'm facing:

My App displays a tableView with time-relevant content (content can get "old") and therefor updates on a regular basis by calling a web service and parsing its xml answer.

so, in order to not display "out of date" information to the user, i want to hide the table and display a "content is being loaded"-label as soon as the app enters an inactive state.

to do so, i react upon calls to - (void)applicationWillResignActive:(UIApplication *)application in my AppDelegate.

that does the job quite well BUT

  • if the user double-taps the home icon to open the task switcher the tableview gets faded out as well
  • the same thing happens if the iphone locks the screen automatically

so, is there a way to distinguish the "type" of inactive state the app enters or any other means to provide me with the possibility to handle those three state-changes differently? Or do I need to walk on a completely different path here?

Thanks for your help
*sam


回答1:


Sam,

I would go at your problem a little differently. What I would do is save an NSDate to NSUserDefaults every time you update your data from the web service. Then whenever your - (void)applicationDidBecomeActive:(UIApplication *)application method in your AppDelegate is called just compare that stored NSDate to the current timestamp ([NSDate date]) and if the difference is greater than whatever your refresh timeout hide the tableView and reload the data.

On the other hand, I think you what you are wanting is applicationDidEnterBackground: instead of applicationWillResignActive:.



来源:https://stackoverflow.com/questions/3299746/difference-between-terminating-an-app-opening-the-task-switcher-and-auto

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