在我的应用程序在后台运行时是否有改变某个值的方法?

huangapple go评论66阅读模式
英文:

Is there a way to change some value when my app is running in background?

问题

我正在开发一个基于位置的应用程序,允许用户与其他用户分享其位置一段时间(15分钟、30分钟、60分钟、1天)。问题是,当用户设定的时间结束时,我需要将其状态更改为false,发送一个HTTP POST请求,停止分享他的位置,即使应用程序在后台运行也要做到这一点。我尝试使用苹果在iOS 13中提供的新的后台任务API,但我在阅读文档时发现它可能需要很多小时,而我需要在设定的时间结束时执行此操作。是否有办法在应用程序内完成此工作,还是应该使用服务器端操作来实现它?

英文:

I'm working in a location based app that allows the user to share his location with some other users for certain periods of time (15 minutes, 30 minutes, 60 minutes, 1 day), the thing is when the time, setted by the user, has finished I need to change his status to false, send a HTTP post with the status and stop sharing his location, even if the app is running in background. I have tried using the new Background Tasks API provided by Apple in iOS 13 but I found reading the documentation that it can take many hours and I need to do it when the time stablished finish. Is there a way to accomplish the job inside the application or should I use server side operations to achieve it?

答案1

得分: 3

考虑一下“显著变化”位置服务。它是一种位置监控功能,即使您的应用程序在后台运行,也可以工作,但不会像标准位置服务那样耗电严重。

它不是基于时间的,但您可以通过编程方式检查是否超过了分配的时间,如果是的话,就关闭显著变化位置服务。

参见使用显著变化位置服务

英文:

Consider the “significant change” location service. It’s a location monitoring capability, which works even if your app is in the background, but isn’t as battery crushing as the standard location services.

It’s not time-based, but you could programmatically check to see whether you’ve exceeded the allotted time, and if so, then turn off significant change location service.

See Using the Significant-Change Location Service.

huangapple
  • 本文由 发表于 2020年1月4日 01:45:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/59583054.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定