iOS的长期运行的背景定时器"地点"背景模式 [英] iOS long-running background timer with "location" background mode

查看:206
本文介绍了iOS的长期运行的背景定时器"地点"背景模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现它发送用户的位置服务器定期长期运行的背景计时器。

I want to implement long-running background timer which sends user's location to server periodically.

要做到这一点,我设置位置模式 UIBackgroundModes ,并调用 beginBackgroundTaskWithExpirationHandler 当应用程序被切换到后台。
CLLocationManager ,我用 startUpdatingLocation 办法(不想使用显著的变化,因为我需要高precision位置)。

To do this, I set location mode for UIBackgroundModes, and call beginBackgroundTaskWithExpirationHandler when the application goes to background. And for CLLocationManager, I use startUpdatingLocation method (don't want to use significant change, because I need high precision location).

但是围绕26分钟该应用后前进到背景,它停止发送位置到服务器。但应用程序不崩溃,所以在我把应用前景,它可以恢复其计时器。

But around 26minutes after the app goes to background, it stops to send location to the server. But the app isn't crashed, so after I bring the app to foreground, it can resume its timer.

26分钟从实验中,与iOS 6.1,iPhone 5。

26minutes is from experiments, with iOS 6.1, iPhone 5.

这里有一些问题,


  1. 我不明白为什么它后26mins 10分钟没有,这被称为后台任务的时限中止。

  1. I can't understand why it suspends after 26mins not 10mins, which is known as time limit for background task.

16mins之前, backgroundTimeRemaining 方法返回双最大值。不过16mins后,从减少 600 ,所以10分钟后暂停后台任务。

Before 16mins, backgroundTimeRemaining methods returns double max value. But after 16mins, it decreases from 600, so it suspends the background task after 10mins.

我已经尝试过拨打 beginBackgroundTaskWithExpirationHandler 到期处理的内部,但是没有用。

I already tried to call beginBackgroundTaskWithExpirationHandler inside of expiration handler, but no use.

如果有任何人谁拥有线索对于这个问题,将大大AP preciated。

If there's anyone who has a clue for this problem, will be greatly appreciated.

推荐答案

https://github.com/voyage11/Location

使用此code.you可以设定你要调用它的时间间隔。我已经尝试了许多codeS,但我发现这是最精确和最电池issue.This也是真棒背景位置服务。 :)

Use this code.you can set time interval you want to call it. I have tried many codes, but i found this as most accurate and least battery issue.This is also awesome for background location service. :)

这篇关于iOS的长期运行的背景定时器"地点"背景模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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