Вопрос

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

I found that battery is getting drained.

Can anyone help me in solving this issue?

Это было полезно?

Решение

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.

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.

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 -

- (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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top