替代startMonitoringSignificantLocationChanges? [英] Alternative to startMonitoringSignificantLocationChanges?

查看:556
本文介绍了替代startMonitoringSignificantLocationChanges?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点初学者到iPhone应用程序开发,但我试图让一个应用程序,基本上更新您的位置每过一段时间时,它不是在前台,这样我就可以映射,当一个人一直在他/她会启动一个应用程序。我以为我可以用startMonitoringSignificantLocationChange,因为工作当应用程序在后台运行,但事实证明,这是非常不准确的。我真的很希望能够设置一个时间间隔,因此,例如,每10分钟的位置将被更新,但我不知道如何去说。任何想法?

I'm somewhat a beginner to iPhone app development, but I'm trying to make an app that basically updates your location every once a while when it's not in the foreground, so that I can then map where a person's been when he/she launches an app. I thought I could use startMonitoringSignificantLocationChange, because that works when the application is in the background, but it turns out that that's very inaccurate. I would really like to be able to set a time interval, so for instance, every 10 minutes the location will be updated, but I have no clue how to go about that. Any ideas?

推荐答案

阅读<一href=\"http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html\">background在苹果网站的定位文档此处

你有一个选择就是声明你的应用为要求连续位置更新。

One option you have is to declare your app as requiring continuous location updates.

应用程序可以声明本身
  需要连续的背景位置
  更新。需要的应用程序
  定期位置更新,无论是在
  前台和后台,应加
  在UIBackgroundModes关键的
  Info.plist文件和设置的值
  此键包含一个数组
  位置字符串。此选项
  用于提供应用程序的
  特定的服务,例如导航
  服务,即涉及保持
  用户通知了他或她的位置的
  每时每刻。关键的presence
  在应用程序的Info.plist文件
  告诉系统它应该允许
  应用程序根据需要在运行
  背景

An application can declare itself as needing continuous background location updates. An application that needs regular location updates, both in the foreground and background, should add the UIBackgroundModes key to its Info.plist file and set the value of this key to an array containing the location string. This option is intended for applications that provide specific services, such as navigation services, that involve keeping the user informed of his or her location at all times. The presence of the key in the application’s Info.plist file tells the system that it should allow the application to run as needed in the background.

这将产生预期的结果,你的应用程序将能够跟踪这些用户走,但你必须要知道,这是最耗电的选择,它被普遍认为是最不理想的选择。然而,如果你试图跟踪某人的步行路程,这是你需要做的之类的事情。

This will have the desired result in that your app will be able to track where the user walks, however you need to be aware that this is the most power hungry option and it is generally regarded as the least desirable option. However if you are trying to track someone's walk, this is the sort of thing you need to do.

即可。你说你只想要获取更新,每10分钟左右。在这种情况下,你最好不要使用这种策略,转而使用显著位置更新。如果关闭这些都将重新启动应用程序,但就像你说的,他们都不是很准确的。诀窍使他们更好地为尽快开始正常位置更新的应用程序得到显著位置更新,你应该得到足够的时间,为了提高您的位置(通过向您发送一些更新)应用程序被再次挂起之前。

HOWEVER. You say you only want to get updates every 10 mins or so. In that case you are best NOT to use this strategy and instead use significant location updates. These WILL restart your app if it is closed but as you say, they are not very accurate. The trick to making them better is to start normal location updates as soon as the app gets the significant location update and you should get enough time for that to improve your location (by sending you some more updates) before the app is suspended again.

这不会是完美的,但它会比只用显著(即基站)的变化更好。

It won't be perfect, but it will be better than just using significant (ie cell tower) changes.

这篇关于替代startMonitoringSignificantLocationChanges?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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