Search Your Question

Have you done battery optimization for gps or api calling?

Ans :

Energy Efficiency in location gathering environment, What can be done.
Stop Location Updates if Accuracy Doesn’t Match Expectations
If your app isn’t receiving updates with the expected level of accuracy, your app should examine the updates it is receiving and determine whether accuracy is improving or staying about the same over time. If accuracy isn’t improving, it’s possible that the desired level of accuracy simply isn’t available at the moment. In this case, stop location updates and try again later so your app doesn’t continuously cause location hardware to draw power.

Stop Location Services When You Aren’t Using Them

With the exception of navigation apps that offer turn-by-turn directions, most apps don’t need location services to be on all the time. Turn location services on only when they’re needed. Then, leave them on just long enough to get a location fix and turn them off again. Unless the user is in a moving vehicle, the current location shouldn’t change frequently enough to be an issue. You can always start location services again later if you need another update.

Reduce Accuracy of Standard Location Updates Whenever Possible

Standard location updates let you specify a degree of accuracy ranging from a few meters to a few kilometers by setting the desiredAccuracy property of the location manager object. Requesting higher accuracy than you need causes Core Location to power up additional hardware and waste power for unnecessary precision. Unless your app really needs to know the user’s position within a few meters, don’t set the accuracy level to best (kCLLocationAccuracyBest) or nearest ten meters (kCLLocationAccuracyNearestTenMeters). Also, be aware that Core Location typically provides more accurate data than you have requested. For example, when specifying an accuracy level of three kilometers (kCLLocationAccuracyThreeKilometers), you may receive accuracy within a hundred meters or so.
By default, standard location updates on iOS devices run with an accuracy level of best. Change these settings to match your app’s requirements. Otherwise, your app will unnecessarily waste energy.
Auto-Pause and Specify an Activity Type When Receiving Location Updates in the Background
Make sure the location manager object’s pausesLocationUpdatesAutomatically property is set to YES to help conserve power.Set the activityType property to let Core Location know what type of location activity your app is performing at a given time — for example, if your app is performing fitness tracking or automotive navigation

Defer Location Updates When Running in the Background

On devices with GPS hardware, you can let the location manager defer the delivery of location updates when your app is in the background. For example, a fitness app that tracks the user’s location on a hiking trail can defer updates until the user has moved a certain distance or a certain period of time has elapsed. Then, it can process the updates all at once. To defer updates, call the location manager object’s allowDeferredLocationUpdatesUntilTraveled:timeout:method and pass it a distance and time that may elapse before the next location update is received. This method is typically called in the locationManager:didUpdateLocations: delegate method in order to defer again, if appropriate, when a deferred location update is received. When a deferred location update is received, the locationManager:didFinishDeferredUpdatesWithError: delegate method is also called, and your app can use this as an opportunity to adjust behavior accordingly — such as increasing or decreasing the deferral distance and time — for the next update

Restrict Location Updates to Specific Regions or Locations

Some apps don’t need to receive continuously location updates, and just need to know when the user is within a certain distance of a location. For example, a grocery app may display new coupons whenever the user nears the store. There are several Core Location APIs that can keep your app informed.
The monitoring techniques described below provide entry and exit notifications only. To determine the user’s actual location when a notification is received, you must call the requestLocation: or startUpdatingLocation: method of the location manager object. These monitoring techniques also require an authorization status of kCLAuthorizationStatusAuthorizedAlways.
Activity Types
  • CLActivityTypeOther
The location manager is being used for an unknown activity.
  • CLActivityTypeAutomotiveNavigation
The location manager is being used specifically during vehicular navigation to track location changes to the automobile. This activity might cause location updates to be paused only when the vehicle does not move for an extended period of time.
  • CLActivityTypeFitness
The location manager is being used to track any pedestrian-related activity. This activity might cause location updates to be paused only when the user does not move a significant distance over a period of time.
  • CLActivityTypeOtherNavigation
The location manager is being used to track movements for other types of vehicular navigation that are not automobile related. For example, you would use this to track navigation by boat, train, or plane. Do not use this type for pedestrian navigation tracking. This activity might cause location updates to be paused only when the vehicle does not move a significant distance over a period of time.
Visit Monitoring
Visit monitoring allows an app to receive entry and exit notifications for specific locations the user visits frequently or for long periods of time such as home, work, or a favorite coffee shop.
To begin monitoring for visits, assign a delegate to the location manager object and call itsstartMonitoringVisits method. Note that calling this method enables all visit updates in your app, not just ones for the current delegate. When enabled, visit events are delivered to the locationManager:didVisit:method of the delegate. If your app isn’t running when a visit event is delivered, your app is relaunched automatically. When visit location updates are no longer required, call stopMonitoringVisits

Register for Significant-Change Location Updates Only as a Last Resort

If GPS-level accuracy isn’t critical for your app, you don’t need continuous tracking, and region or visit monitoring isn’t more appropriate for your app, you can use the significant-change location service instead of the standard one.
Region and visit monitoring are sufficient for most use cases and should always be considered before significant-change location updates. In the event significant-change location updates are needed, keep in mind the following, which can actually result in higher energy use if not employed effectively:
  • > Significant-change location updates wake the system and your app once every 15 minutes, at minimum, even if no location changes have occurred.
  • > Significant-change location updates run continuously, around the clock, until you stop them.
To start significant-change location updates, call the startMonitoringSignificantLocationChanges method of the location manager object. When you’re done, call stopMonitoringSignificantLocationChanges .

No comments:

Post a Comment