[英]How to know if my app is currently used in ios
I want to perform a task continuously in my iOS application. 我想在我的iOS应用程序中不断执行任务。 If my application is in the foreground, it's working as expected.
如果我的应用程序在前台,它正在按预期工作。 But the moment it enters into the background or is in sleep mode, it stops working.
但是当它进入后台或处于睡眠模式时,它就会停止工作。
How can I implement this in iOS? 我如何在iOS中实现这一点?
You can use the Finite-Length tasks to execute some task when your app is going in to the background. 当您的应用程序进入后台时,您可以使用有限长度任务来执行某些任务。 This will allow your app the to finish a task with a given time (10min. max).
这将允许您的应用程序在给定时间内完成任务(最多10分钟)。
The other option is to look if your app falls in any of the background modes . 另一种选择是查看您的应用是否属于任何后台模式 。 But be aware that is you misses the background mode to keep you app a live in the background apple will reject your app.
但要注意的是,你错过了背景模式让你的应用程序在后台运行苹果将拒绝你的应用程序。
If the task is an update task, like to retrieve new information, you should move this task to a server and use Push Notifications to alert the user of update. 如果任务是更新任务,比如要检索新信息,则应将此任务移至服务器并使用推送通知来提醒用户更新。 You can even combine it with a background fetch which will allow you app the retrieve the information in the background.
您甚至可以将它与后台提取相结合,这将允许您应用程序在后台检索信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.