iOS-应用终止时的后台服务 [英] iOS - Background Services when app is terminated

查看:95
本文介绍了iOS-应用终止时的后台服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果终止了应用程序,后台模式功能(例如后台获取和位置更新)是否起作用?还是仅在应用进入后台时才起作用?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆