如何使用CLLocationManager限制应用程序的电池消耗

时间:2022-01-28 16:55:17

I am developing an iPhone application in which I am updating current location of user from time to time using GPRS.

我正在开发一个iPhone应用程序,我正在使用GPRS不时更新用户的当前位置。

I found that battery is getting drained.

我发现电池正在耗尽。

Can anyone help me in solving this issue?

任何人都可以帮我解决这个问题吗?

1 个解决方案

#1


6  

You are correct in your observation. GPS services is power-intensive operation. It involves powering up the onboard radios and querying the available cell towers, Wi-Fi hotspots, or GPS satellites, which can take several seconds. Having the standard location service running for extended periods can drain the device’s battery.

你的观察是正确的。 GPS服务是功率密集型操作。它涉及启动机载无线电并查询可用的蜂窝塔,Wi-Fi热点或GPS卫星,这可能需要几秒钟。让标准位置服务长时间运行会耗尽设备的电池电量。

iOS folks have devised a solution for this. Its called signification location change. The significant-change location service offers a low-power location service for devices with cellular radios. This service is available only in iOS 4.0 and later and can also wake up an app that is suspended or not running. The way this works is you subscribe to this service and request iOS to inform you incase "signification location" change happens from the user. The definition of "significant" is not in your hands. Actually, this is what saves battery. You dont query for location. You get updates.

iOS人员为此设计了一个解决方案。它称为意义位置变化。重大变化定位服务为具有蜂窝无线电的设备提供低功率定位服务。此服务仅在iOS 4.0及更高版本中可用,并且还可以唤醒暂停或未运行的应用程序。这种方式的工作方式是您订阅此服务并请求iOS通知您,用户可能会发生“表示位置”更改。 “重要”的定义不在您手中。实际上,这就是节省电池的原因。你不查询位置。你得到更新。

In my opinion, this API is excellent and gives a "fairly" accurate position. Unless you are building a tracking app, this API is the way to go as its easy on the battery. I cannot tell you the number of apps (paid & free) I have ruthlessly deleted simply because they were abusing location services and draining my battery. Imagine a user's iPhone unusable in half a day due to dead battery. Be very mindful of this. The way to start this service is -

在我看来,这个API非常出色,并且提供了“相当”准确的位置。除非您正在构建一个跟踪应用程序,否则这个API就可以轻松使用电池了。我无法告诉你我被无情删除的应用程序数量(付费和免费)只是因为他们滥用位置服务和耗尽我的电池。想象一下,由于电池耗尽,用户的iPhone在半天内无法使用。要非常注意这一点。启动此服务的方法是 -

- (void)startSignificantChangeUpdates
{
    // Create the location manager if this object does not
    // already have one.
    if (nil == locationManager)
        locationManager = [[CLLocationManager alloc] init];

    locationManager.delegate = self;
    [locationManager startMonitoringSignificantLocationChanges];
}

After this as with the standard location services, location data is delivered to the delegate object. and you can use it based on your use-cases. More info at Apple Location Docs

在此之后,与标准位置服务一样,位置数据被传递到委托对象。并且您可以根据您的用例使用它。有关Apple Location Docs的更多信息

#1


6  

You are correct in your observation. GPS services is power-intensive operation. It involves powering up the onboard radios and querying the available cell towers, Wi-Fi hotspots, or GPS satellites, which can take several seconds. Having the standard location service running for extended periods can drain the device’s battery.

你的观察是正确的。 GPS服务是功率密集型操作。它涉及启动机载无线电并查询可用的蜂窝塔,Wi-Fi热点或GPS卫星,这可能需要几秒钟。让标准位置服务长时间运行会耗尽设备的电池电量。

iOS folks have devised a solution for this. Its called signification location change. The significant-change location service offers a low-power location service for devices with cellular radios. This service is available only in iOS 4.0 and later and can also wake up an app that is suspended or not running. The way this works is you subscribe to this service and request iOS to inform you incase "signification location" change happens from the user. The definition of "significant" is not in your hands. Actually, this is what saves battery. You dont query for location. You get updates.

iOS人员为此设计了一个解决方案。它称为意义位置变化。重大变化定位服务为具有蜂窝无线电的设备提供低功率定位服务。此服务仅在iOS 4.0及更高版本中可用,并且还可以唤醒暂停或未运行的应用程序。这种方式的工作方式是您订阅此服务并请求iOS通知您,用户可能会发生“表示位置”更改。 “重要”的定义不在您手中。实际上,这就是节省电池的原因。你不查询位置。你得到更新。

In my opinion, this API is excellent and gives a "fairly" accurate position. Unless you are building a tracking app, this API is the way to go as its easy on the battery. I cannot tell you the number of apps (paid & free) I have ruthlessly deleted simply because they were abusing location services and draining my battery. Imagine a user's iPhone unusable in half a day due to dead battery. Be very mindful of this. The way to start this service is -

在我看来,这个API非常出色,并且提供了“相当”准确的位置。除非您正在构建一个跟踪应用程序,否则这个API就可以轻松使用电池了。我无法告诉你我被无情删除的应用程序数量(付费和免费)只是因为他们滥用位置服务和耗尽我的电池。想象一下,由于电池耗尽,用户的iPhone在半天内无法使用。要非常注意这一点。启动此服务的方法是 -

- (void)startSignificantChangeUpdates
{
    // Create the location manager if this object does not
    // already have one.
    if (nil == locationManager)
        locationManager = [[CLLocationManager alloc] init];

    locationManager.delegate = self;
    [locationManager startMonitoringSignificantLocationChanges];
}

After this as with the standard location services, location data is delivered to the delegate object. and you can use it based on your use-cases. More info at Apple Location Docs

在此之后,与标准位置服务一样,位置数据被传递到委托对象。并且您可以根据您的用例使用它。有关Apple Location Docs的更多信息