简体   繁体   English

iOS 应用程序在后台连续运行

[英]iOS app to run continuously in background

I want my iOS apps to run continuously in background 24/7 I tried many options like background location updated with background task expiration handler, but later after some times it seems that the application gets suspended in background and user is brought back to the root view controller.我希望我的 iOS 应用程序在后台 24/7 连续运行我尝试了许多选项,例如使用后台任务到期处理程序更新的后台位置,但过了一段时间后,似乎应用程序在后台暂停并且用户被带回根视图控制器。 Any help will be appreciated.任何帮助将不胜感激。

You should read this page of Apple Programming Guide : Background Execution您应该阅读 Apple Programming Guide 的这一页: 后台执行

It is not allowed to run background tasks 24/7.不允许 24/7 全天候运行后台任务。 But you can use many different ways.但是您可以使用许多不同的方式。

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended.对于需要更多执行时间来实现的任务,您必须请求特定权限才能在后台运行它们而不会被挂起。 In iOS, only specific app types are allowed to run in the background:在 iOS 中,只允许特定类型的应用程序在后台运行:

  • Apps that play audible content to the user while in the background, such as a music player app在后台向用户播放有声内容的应用程序,例如音乐播放器应用程序
  • Apps that record audio content while in the background在后台录制音频内容的应用程序
  • Ap ps that keep users informed of their location at all times, such as a navigation app让用户随时了解其位置的应用程序,例如导航应用程序
  • Apps that support Voice over Internet Protocol (VoIP)支持互联网协议语音 (VoIP) 的应用程序
  • Apps that need to download and process new content regularly需要定期下载和处理新内容的应用
  • Apps that receive regular updates from external accessories从外部配件接收定期更新的应用程序
  • Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services.实现这些服务的应用程序必须声明它们支持的服务并使用系统框架来实现这些服务的相关方面。

Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.声明服务让系统知道您使用了哪些服务,但在某些情况下,实际上是系统框架阻止了您的应用程序被挂起。

You simply can't.你根本做不到。 Apple don't give any mean for an app to ensure background execution. Apple 没有为应用程序提供任何手段来确保后台执行。 iOS will give you processing time whenever it feel like it, and you cannot control that. iOS 会随时为您提供处理时间,而您无法控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM