I have tried the significant location change in the latest iOS 8 update but the Core Location manager method
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
is never called.
When using method startUpdatingLocation the method above is called.
Everything worked in iOS 7 for the app. I need to update to iOS 8.
Share your experience.
I'm going to guess that you're not following the instructions here:
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_class/index.html#//apple_ref/occ/instm/CLLocationManager/startMonitoringSignificantLocationChanges
Events are going to be accumulated while your app is not running. Your app launches and must immediately create a location manager and start significant location updates all over again in order to receive that accumulated information.
If you are updating to iOS 8 be sure to make the changes in the property list (.plist) file: NSLocationWhenInUseUsageDescription and/or NSLocationAlwaysUsageDecription : http://matthewfecher.com/app-developement/getting-gps-location-using-core-location-in-ios-8-vs-ios-7/
Related
Hi recently with the iOS 9 GM seed version out,I have seen location update(allowDeferredLocationUpdatesUntilTraveled:timeout:) not getting deferred. I am getting error kCLErrorDeferredFailed - The location manager did not enter deferred mode for an unknown reason.
Its because of this error its not entering the defer mode at all and location updates are firing continuously .
The same code used to work in iOS 8.4 and below versions.Its draining my device's battery by a huge percentage.
Is there anything we need to explicitly set or mention for iOS 9.Didn't find anything from Apple documentation?
-(void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
if (!self.deferringUpdates) {
[self.locationManager allowDeferredLocationUpdatesUntilTraveled:CLLocationDistanceMax timeout:30];
self.deferringUpdates = YES;
}
}
-(void)locationManager:(CLLocationManager *)manager
didFinishDeferredUpdatesWithError:(NSError *)error {
// Stop deferring updates
self.deferringUpdates = NO;
}
I also set the allowsBackgroundLocationUpdates property but even that didn't help.
self.locationManager.allowsBackgroundLocationUpdates=YES;
In iOS 9 and later, regardless of deployment target, you must also set the allowsBackgroundLocationUpdatesproperty of the location manager object to YES in order to receive background location updates. By default, this property is NO, and it should remain this way until a time when your app actively requires background location updates.
Reduce Location Accuracy and Duration
Please let me know what additional I need to make
Thanks
Please read the discussion on the API reference page.
A few things to try, as mentioned here
Kill all apps from multitasking bar
Verify that no other app is using location services
Unplug the device from debugger and MacBook (Verify it is still getting call by logging didUpdateLocations to a file)
Make sure that the device supports deferred updates
Make sure that the distanceFilter is None, the desiredAccuracy is Best
Since yesterday, I have a problem with monitoring region working with CLLocationManager
PS: my project was working perfectly I'm testing it everyday, but today this delegate method was called after 1 minute of entering a region
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{}
and now it's no more getting called I have made another project only with CLLocationManager for testing the delegate method and the same thing is happening.
Can you just tell me what the hell this could be?
[UPDATE]
i found this helpful link about iOS Region Monitoring after iPhone Restart
Just check that below service is on or off.
[CLLocationManager regionMonitoringAvailable] returns YES
CLLocationManager.monitoredRegions contains valid regions
Apple document specified that events make take between 3-5 minutes to fire.
Hope this help you.
Does locationManager:didDetermineState:forRegion: get called?
Do you call requestStateForRegion: after startMonitoringForRegion:?
Is this in background or foreground?
In my app, I am using the Boundary-Crossing Events for a Geographical Region to determine if a user has visited a location. This is working as expected when users have installed the app prior to visiting the location, however some users will be installing the app while they are at the event, and therefore are already within the location when the event is installed and so iOS does not treat this as a boundary crossing.
Is there a way to force iOS to trigger the locationManager:didEnterRegion method if the startMonitoringForRegion method is called while the device is currently within the region to monitor?
In iOS7, you can use requestStateForRegion: method of the CLLocationManager class to check whether the user is already inside a fence.
You need to implement below delegate method to receive the event.
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region {
}
Thanks to this article for the answer (as well as a solution for iOS version < 7: http://hayageek.com/ios-geofencing-api/
I want to attach a listener in IOS which is invoked whenever GPS is turned ON or OFF from settings. Listener should be invoked no matter my application is running, in background or has been stopped. I have this functionality that i need to keep GPS settings of a user who has installed app, on server side, so whenever GPS is changed i must notify the server.
I guess there isn't any listener,
You can Use Delegate method of CLLocationManager.
Use this delegate method for getting location - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
Form this [locations lastObject] you can latest location send location to server.
You can not get location when app is stopped.
As of now, there is no such notification exists.
However you can create and start a timer (NSTimer) that will regularly poll whether GPS is enabled or not, using 'CLLocationManager locationServicesEnabled' method.
Within your class, you can have a bool iVar that will be set / reset based on return value. Whenever its value is altered, you can notify server about service start / stoppage.
GPS signal is lost when App is resumed from long time suspend mode.
And/or after user goes into a building where GPS is weak and then resumes the App.
The blue dot disappears and the map is centered at lat:0 long:0 ( which is somewhere in
the ocean near Nigeria-Africa )
If you launch another GPS app at that point in time, such as Apple Maps,
you DO see the blue dot, even if not so accurate.
The only way a user can fix it - is by killing my app completely and start it again.
It happens on both iOS 5.x and iOS 6.x.
Before going into details, I would really like to ask:
Does anyone encounter this problem ??
Its very annoying but, I couldn't find anyone complaining about this
anywhere on the web - very weird.
I'm using normal CLLocation with showUserLocation=YES,
Nothing magical, no special accuracy tuning or whatever, just simple default
implementation.
I have already tried restarting every possible component when App is resumed;
showUserLocation=NO;
showUserLocation=YES;
or
[locationManager stopUpdatingLocation];
[locationManager startUpdatingLocation];
or
even releasing locationManager and initialize it again doesn't help!
( also tried restarting it with a delay using dispatch_after )
Is there any programmatic way to force RESET the GPS signal or CLLocation in ios ?
Will appreciate any relevant discussion!
I Think you default Location is set "None" so this type of issue created.
Go to
Edite Scheme..
|
|
"Run YourProjectName" / Left Hand Side
|
|
Select "Option" Tab
|
|
Default Location
|
|
Choose any Location such like , "London England"
When you say that you've tried stopping/starting the CLLocationManager object, are you saying that the call-back you get in your delegate gives you a 0,0 coordinate, or are you trying to access the location directly using the location property in CLLocationManager?
I work on a location based app and one thing I can tell you is that you cannot count of directly getting the location of a CLLocationManager object. The only reliable way to get location information is to rely on the callback of the CLLocationManager class by implementing
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
The way I handle CLLocationManager in my app (now I'm not saying this is optimal or ideal for your use case but it does allow us to provide a solid location-based experience to the user on app launch/resume)
Wrap the CLLocationManager into a location management class (usually using a singleton) - I think this can be a subclass of CLLocationManager but in my case it's just a subclass of NSObject with a CLLocationManager object as a property
Store the last known valid location in this singleton, and then write it to disk (NSUserDefaults or another location - need to re-check if you're allowed to store user location in NSUserDefaults but we've done it in our app and doesn't seem to affect the approval process)
Re-implement a way to get the current location in your custom class - basically check if CLLocationManager is returning 0,0 and if it is, return your cached position instead
Not strictly necessary but if you have multiple views/pages that need to use the location, implementing the observer model works well (since your singleton is now CLLocationManager's delegate, you need to have a way to pass this information on to your view controllers).
With the above, on my map page (or wherever I'm displaying user location) - I basically update the map with the cached location once (in viewDidLoad) and then I allow one update to the map through the delegate-callback. Once that call-back is received, I then set showsUserLocation to YES (if the call-back isn't called, then you don't have a valid location yet and so setting showsUserLocation at that point doesn't do anything).
I hope this helps and feel free to let me know if you have any further questions!