iOS-应用终止时的后台服务 [英] iOS - Background Services when app is terminated
问题描述
如果终止了应用程序,后台模式功能(例如后台获取和位置更新)是否起作用?还是仅在应用进入后台时才起作用?
Do background mode functions like Background fetch and Location update work if the app is terminated? Or it only works if the app enters background?
谢谢
推荐答案
是的,(在大多数情况下)可以正常工作,前提是您正确设置了所有内容并获得了权限.您的应用需要至少启动1次,才能订阅更新.
Yes, it works (most of the time), if you set up everything correctly and have the permissions. Your app need's to be launched at least 1 time, so it can subscribe to the updates.
对于后台获取,请在didFinishLaunching
方法中设置UIApplication.shared.setMinimumBackgroundFetchInterval(3600)
,实施performFetchWithCompletionHandler
方法,并在后台模式下启用后台获取.
注意尽快执行此操作,并尽快调用completionHandler.
For background fetch, set UIApplication.shared.setMinimumBackgroundFetchInterval(3600)
at the didFinishLaunching
method, implement the performFetchWithCompletionHandler
method, and enable the Background Fetch in the Background Modes.
Pay attention to do it as quickly as possible, and call the completionHandler as soon as possible.
Read more on Updating Your App with Background App Refresh here
对于通知更新,还必须将CLLocationManager
对象的allowsBackgroundLocationUpdates
属性设置为true
,并在后台模式下启用位置更新.
For notification updates, you must also set the allowsBackgroundLocationUpdates
property of your CLLocationManager
object to true
, and enable the Location updates in the Background Modes.
这篇关于iOS-应用终止时的后台服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!