I have a locate me button in my app. The behaviour when user taps the button is quite strait forward. If location services is switched off I show an alert view to user about it otherwise starts updating location.
To check that locations services is enabled/disabled I start CLLocationManager and if I get the error code kCLErrorDenied in
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
I show the UIAlertView that the location service is disabled.
It works good but the problem happens when I start CLLocationManager for the first time (or user resets his locations services settings). In this situation system shows alert which asks user if he's ok that app will use location services and if user does not allow to use location services I immediately get error in
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
and should show second app's alert that locations services are disabled for the app but it's not really smart because user disabled it just second ago.
So the question is how to find out that system location services alert was on screen and user disabled location services second ago to not show second alert?
Related
Hello I am using here UIWebView and load request for map . Now I have all done successfully but when I run app first time then Pop up show, I am attaching image here
Now I want to ask how to access this pop up actions (Don't allow and oK) ,because this is by default generated first time when we app run. I don't know how to access "Ok" button I want to write some code on "Ok" button.
So please anyone tell me how to access these pop up buttons in my case.
Implement CLLocationManagerDelegate Protocol to get call back event for that alert button pressed by authorization status.
locationManager:didChangeAuthorizationStatus:
Tells the delegate that the authorization status for the application changed.
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
There are various authorization status provided mention as follows :
typedef enum {
kCLAuthorizationStatusNotDetermined = 0,
kCLAuthorizationStatusRestricted,
kCLAuthorizationStatusDenied,
kCLAuthorizationStatusAuthorized,
} CLAuthorizationStatus;
kCLAuthorizationStatusNotDetermined
The user has not yet made a choice regarding whether this app can use location services.
kCLAuthorizationStatusRestricted
This app is not authorized to use location services. The user cannot change this app’s status, possibly due to active restrictions such as parental controls being in place.
kCLAuthorizationStatusDenied
The user explicitly denied the use of location services for this app or location services are currently disabled in Settings.
kCLAuthorizationStatusAuthorized
This app is authorized to use location services.
You can edit the message that is shown on UIAlertView, but you can not access the control of ok button, because iOS don't provide a delegate to access this button.
The alert is only shown for the first time, you launch the app and not after that.
You can only control the condition to present this alert but you cannot control the ok button
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.
How can I observe and call a method when the location services options change? For example, my app runs location services in the background, i.e. the option in Settings is set to always. What if the user changes the option while my app is still running, how can observe changes and make changes in my app accordingly?
Implement the CLLocationManagerDelegate method
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
From the docs:
"This method is called whenever the application’s ability to use location services changes. Changes can occur because the user allowed or denied the use of location services for your application or for the system as a whole."
Is there a way to delay code from running until the user has answered the current location prompt? My app fetches annotations and puts them on the map. When the app launches for the first time and the user allows current location it fails to fetch any annotations because the code already ran without receiving a current location. Thanks in advance.
You can implement the following CLLocationManagerDelegate method:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
and only show your annotations after that method is called. It will be called when the user accepts or rejects the current location prompt.