Does DesiredAccuracy property affect region monitoring ? My guess is that it just affects location updates, but I want to be sure. Apple documentation doesn't specifically say anything about that.
No, it won't affect region monitoring.
But a delay may be observed based on which source the framework fetched the location updates.
Setting a desiredAccuracy property will enable LocationFramework to provide you location updates & significant location changes based on the property. If you choose it to be a value "best", the framework will take care of sending location updates as per that value, depending on the location updates being fetched from either wifi, or cellular or GPS.
If you set it to "navigation", you will get location updates from all the possible ways the framework can detect the location changes.
Hope that helps.
Related
I want to get the different locations of the users in order to display him the trips he did. But in order to save my user's battery, I want to get his location just every 10 seconds with my CLLocation manager.
I first thought about not implementing the 10 seconds interval and get the user's location every time he move with the didUpdateLocations of the CLLocationManager, but when I simulate a drive I get new location every second and I think this is really bad for the battery, am I right ?
Do not try to second guess the location manager. Your job is to set its properties appropriately, such as distanceFilter, desiredAccuracy and activityType. Apple will use every trick in the book to keep battery usage reasonable given your settings. As the docs tell you:
Core Location manages power aggressively by turning off hardware when it is not needed. For example, setting the desired accuracy for location events to one kilometer gives the location manager the flexibility to turn off GPS hardware and rely solely on the WiFi or cell radios, which can lead to significant power savings.
If the goal is track location in the background, there are special modes for that, which save even more.
Check location every 10 second a lot frequent, it will be drain user's battery too fast.
If you would save battery, you should learn apple guide about location manager.
You need use distanceFilter and desiredAccuracy
Base guide CLLocationManager
Energy Efficiency Guide for iOS Apps
Location Awareness Programming Guide - Tips for Conserving Battery Power
Update
Also you can check how fast user moving CLLocation have speed and adjust activityType
I'm doing an app to trigger a local notification when a region is entered.
However, sometimes when the phone is locked, the notifications didn't pop up even I've been in the region area for a while. The notification popup will show only when the power/home button is pressed(phone still in locked mode).
In general, all seems to be working except that sometimes the notification will show only when power/home button is pressed to awake the phone although it is still locked.
Hope someone can enlighten me please! =)
According to the developer documentation. In core-location framework, two services can give you the current location information.
The standard location service is a configurable, general-purpose solution for getting location data and tracking location changes for the specified level of accuracy.
The significant-change location service delivers updates only when there has been a significant change in the device’s location, such as 500 meters or more.
You need to use standard location services to keep monitoring location in background
If your iOS app must keep monitoring location even while it’s in the background, use the standard location service and specify the location value of the UIBackgroundModes key to continue running in the background and receiving location updates. (In this situation, you should also make sure the location manager’s pausesLocationUpdatesAutomatically property is set to YES to help conserve power.)
Working on Apple's iBeacons, here is some code that I use to initialise CLLocationManager and start monitoring for beacon regions:
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.pausesLocationUpdatesAutomatically = false;
self.locationManager.allowsBackgroundLocationUpdates = true;
self.locationManager.delegate = self;
How much does pausesLocationUpdatesAutomatically play a part in region monitoring?
The official documentation says:
A Boolean value indicating whether the location manager object may
pause location updates.
However the "Getting Started with iBeacons" official guide does not mention this. Plus it was last updated in 2014 and I haven't found any more on this.
How does this affect battery life?
How does this affect the iBeacon region detection?
Location updates and beacon detection are not related.
iBeacon detection uses the Bluetooth chipset and doesn't provide you with a location as such. It just tells you that you entered (or exited) a CLBeaconRegion.
CLCircularRegion detection is different; this relies on determining the user's latitude and longitude; either by GPS or WiFi. GPS has a significant impact on battery life.
So, the short answer is that pausesLocationUpdatesAutomatically shouldn't have any impact on beacon detection.
If you check full description for pausesLocationUpdatesAutomatically in documentation, you'll see explanation:
Allowing the location manager to pause updates can improve battery
life on the target device without sacrificing location data. When this
property is set to YES, the location manager pauses updates (and
powers down the appropriate hardware) at times when the location data
is unlikely to change. For example, if the user stops for food while
using a navigation app, the location manager might pause updates for a
period of time. You can help the determination of when to pause
location updates by assigning a value to the activityType property.
And for activityType:
The location manager uses the information in this property as a cue to
determine when location updates may be automatically paused. Pausing
updates gives the system the opportunity to save power in situations
where the user's location is not likely to be changing. For example,
if the activity type is CLActivityTypeAutomotiveNavigation and no
location changes have occurred recently, the radios might be powered
down until movement is detected again.
If you turn on pausesLocationUpdatesAutomatically it'll start to monitor significant location changes and save battery since it is not using GPS so often.
Region detection, in such case, will occur when there is significant change, so this check will be performed less often, tricky part here is how much is region detection important for you - if you decide to save battery will significant change detection be ok for region detection.
I hope this helps.
In Android whenever you get location object you could call "location.getProvider" on the instance to get value like "wifi". Is there something similar in iOS (CLLocation)?
The Location Awareness Programming Guide says:
The [CoreLocation] framework uses information obtained from the built-in cellular, Wi-Fi, or GPS hardware to triangulate a location fix for the device. It reports that location to your code and, depending on how you configure the service, also provides periodic updates as it receives new or improved data
Having said that, you do not have access to how precisely the CLLocationManager determined your location (other than, if you used significant change, that it probably used cell towers). You theoretically could use Reachability to see if you have Wi-Fi availability, but you have no assurances as to what mix of GPS, cellular, and Wi-Fi it used to get your location (even if you happen to have WiFi connection).
What you do have is horizontalAccuracy, which tells you approximately how accurate the location you received is. From a user's perspective, that's probably a more important piece of information.
There isn't a concept of what system provided you with the location on iOS. What you can do is check what the accuracy of the location is. Based on how precise the location is, you can probably surmise if the location was provided by a GPS signal.
The reason this isn't given is that iOS will provide you with an initial location which won't be very accurate (likely based on geo-ip or cell triangulation) and then update the location with more and more precise coordinates if GPS is available.
If your application requires the accuracy provided by a GPS chip, you can add UIRequiredDeviceCapabilities = gps to your Info.plist.
I'm building a little prototype app to test Location Services. My app uses both -startUpdatingLocation and -startMonitoringSignificantLocationChanges (for background processing).
In both cases, I'm trying to send a json object to a server with the location data I get, but I'd like to be able to also send some sort of identifier so I can determine which mode of location service was used to acquire the data (GPS, wifi, tower or at least if it was through one of the two services above.
I'm setting up my CLLocationManager in the AppDelegate if that makes any difference.
Thanks
The sources that CLLocationManager uses are not provided. However, you can determine whether GPS is allowed to turn off by setting the desiredAccuracy property. As the documentation notes, an accuracy of 1 kilometer may have the GPS turn off.
For example, setting the desired accuracy for location events to one kilometer gives the location manager the flexibility to turn off GPS hardware and rely solely on the WiFi or cell radios. Turning off GPS hardware can lead to significant power savings.
You don't exactly control the GPS because other apps may be requesting a greater accuracy in the background.
You can roughly guess what was used for determining your location by examining your CLLocation object. Each CLLocation object has a property called horizontalAccuracy. This value is measured in meters. If it is less than 1 kilometer then GPS was probably used.