问题描述
我们正在开发一款具有较高GPS使用率的应用程序,我们无法优化电池寿命。
即使设备没有移动,根据代码也不会发生明显的电池泄漏
。 下面是代码:
locationManager = [ [CLLocationManager alloc] init];
locationManager.distanceFilter = 100;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
理想情况下,我们希望每20分钟触发一次GPS(如果没有位置更改,则保存电池)或者如果有位置变化,则每5分钟一次。根据我的开发人员,这是不可能的
以前我们使用 kCLLocationAccuracyBest
,它耗电非常快,现在我们使用 kCLLocationAccuracyHundredMeters
。
startUpdatingLocation - 获取GPS坐标。还有另一个电话startMonitoringSignificantLocationChanges,它可以获得AGPS坐标,我相信当电池塔改变时,它会返回坐标,因此消耗电池非常快。
distanceFilter - 在更新事件生成之前,设备必须横向移动的最小距离(以米为单位测量)。在距离过滤器的基础上,我们从设备获取GPS定位,然后我们将更新的GPS坐标发送到服务器。 任何帮助将不胜感激
谢谢!
这正是它所做的,但是你可以跳出对所需功率的结论。 GPS接收器和WiFi收发器可用于帮助确定位置,但它们是必须通电才能使用的额外设备。但是iPhone这样的手机无论如何都需要与最近的手机大厅保持联系,以便接听电话,所以使用手机信号塔作为位置信息源应该在功率方面非常高效。以下是说: -startMonitoringSignificantLocationChanges
:
它还将服务描述为提供巨大的节能,因此它似乎是您描述的工作的正确工具。当然,如果您同时 使用标准位置更新机制,则不会看到节能,所以请确保您没有使用两者。
听起来好像在这里有一些误解。如果这是你想要的,你可以每隔20分钟启动一次GPS以获得修复,尽管你无法从背景中做到这一点。即使它在后台运行,重要的位置更改服务也会通知您的应用程序,因此您的开发人员可能正在讨论后台更新。
We are developing an app that has heavy GPS usage, and we are unable to optimize the battery life.
Even when the device is not moved, there is significant battery drainage that, according to the code, should not happen.
Here is the code:
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = 100;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
Ideally we want to trigger GPS every 20 minutes (if there is no location change then save battery) OR every 5 minutes if there is location change. According to my developer this cannot be done
Previously we were using kCLLocationAccuracyBest
, which was consuming battery very fast and now we are using kCLLocationAccuracyHundredMeters
.
startUpdatingLocation - is to get the GPS coordinates. There is another call startMonitoringSignificantLocationChanges which is to get AGPS coordinates which I believe returns the coordinates whenever cell tower will change, and hence consumes battery really fast.
distanceFilter - The minimum distance (measured in meters) a device must move laterally before an update event is generated. On the basis of distance filter we get the GPS fix from the device and then we send the updated GPS coordinates to the server.
Any help will be greatly appreciatedThank you!
That's exactly what it does, but you're jumping to conclusions about the power required for that. The GPS receiver and WiFi transceiver can be used to help determine location, but they're extra devices that have to be powered to be useful. But mobile phones like the iPhone need to keep in touch with the nearest cell tower anyway in order to receive phone calls, so using cell towers as a source of location information should be very efficient with respect to power. Here's what the CLLocationManager reference page says about -startMonitoringSignificantLocationChanges
:
It also describes the service as providing "tremendous power savings," so it seems the right tool for the job you describe. Of course, if you're also using the standard location updating mechanism at the same time you won't see that power savings, so make sure you're not using both.
It sounds like there's some sort of misunderstanding here. You can certainly fire up the GPS every 20 minutes to get a fix if that's what you want, although you can't do that from the background. The significant location change service will notify your app even if it's running in the background, so perhaps your developer is talking about background updates.
这篇关于iPhone GPS - 电池消耗非常快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!