简体   繁体   English

如何在iOS 12的后台运行iOS应用

[英]How to run iOS app in background on iOS 12

I have an app that runs in the background without problem on iOS 8, 9, 10, and 11. However, it stops running in the background on iOS 12.1 (it's killed after 180 seconds). 我有一个可以在iOS 8、9、10和11上在后台运行的应用程序。但是,它停止在iOS 12.1上在后台运行(180秒后被杀死)。

I notice that some apps still work ok like Skype, Facebook, Viber, etc. and I notice that Apple released iOS 12.2 now. 我注意到某些应用程序仍然可以正常运行,例如Skype,Facebook,Viber等,并且我注意到Apple现在发布了iOS 12.2。

Does anyone know how these apps can run in the background without any problems? 有谁知道这些应用程序如何在后台运行而不会出现任何问题?

If your app is killed after 180 seconds, it is because your app ask the system to continue running for a while when your app goes to background. 如果您的应用程序在180秒后被杀死,那是因为您的应用程序在后台运行时要求系统继续运行一段时间。

This request is done using [UIApplication beginBackgroundTaskWithName] : https://developer.apple.com/documentation/uikit/uiapplication/1623051-beginbackgroundtaskwithname?language=objc 此请求使用[UIApplication beginBackgroundTaskWithName]https : //developer.apple.com/documentation/uikit/uiapplication/1623051-beginbackgroundtaskwithname? [UIApplication beginBackgroundTaskWithName] = [UIApplication beginBackgroundTaskWithName]

As stated in the documentation, 如文档中所述,

This method requests additional background execution time for your app. 此方法为您的应用请求额外的后台执行时间。

This additional time was 180 seconds (I think it's closer to 30 seconds since iOS 12). 这额外的时间是180秒(我认为自iOS 12以来已接近30秒)。

If you need yourapplication to be really running in background, you have to declare a background mode in your application's capabilities in Xcode: 如果您需要应用程序真正在后台运行,则必须在Xcode中的应用程序功能中声明一个background mode

在此处输入图片说明

That's the way the applications you listed works in background (essentially Voice over IP mode). 这就是您列出的应用程序在后台(基本上是Voice over IP模式)工作的方式。

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

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