Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do detect GPS on/of at iPhone xcode and how can we know about our application isn't allowed using gps?

I want to make application that will use GPS, as we know at first time user use our application that need gps/current location, there is a pop up that asking for permission, the problem is.. example:

the user choose not allow, and then how can we know the user make our application can't access to her/his gps to know his/her location? because my application need CurrentLocation, so if I can detect what user choose, I want to make a Pop Up like first Pop Up that asking for permission again.

or any code that can make gps turn on/off by my application?

Imagine if the user does not allow by mistake? Is there away for my application to reask the user?

What should application like Yelp do when location is not available?

like image 683
user4951 Avatar asked Dec 16 '22 11:12

user4951


2 Answers

As of iOS 4.2, the class on which you’re implementing CLLocationManagerDelegate’s methods (like -locationManager:didUpdateToLocation:fromLocation:) should also implement -locationManager:didChangeAuthorizationStatus:. There are four statuses that that method will receive; to check for your app being unable to use location services, look for kCLAuthorizationStatusRestricted—when the user is unable to allow access to location services—and kCLAuthorizationStatusDenied—when the user has explicitly refused your application access to location services. In both cases, the appropriate thing to do is to inform the user (via an alert view or whatever) that your application relies on being able to access their location and that they may be able to re-grant it that access in the Settings app. You can also check your app’s authorization status at any time using the CLLocationManager class method +authorizationStatus.

Pre-4.2, unfortunately, none of that is available, and you’ll need to use the +locationServicesEnabled method that sosbom’s answer mentions.

like image 158
Noah Witherspoon Avatar answered Dec 28 '22 06:12

Noah Witherspoon


Read this: Location Awareness Programming

The key line is this:

Determining Whether Location Services Are Available Every iOS-based device is capable of supporting location services in some form but there are still situations where location services may not be available:

The user can disable location services in the Settings application. The user can deny location services for a specific application. The device might be in Airplane mode and unable to power up the necessary hardware. For these reasons, it is recommended that you always call the locationServicesEnabled class method of CLLocationManager before attempting to start either the standard or significant-change location services. (In iOS 3.x and earlier, check the value of the locationServicesEnabled property instead.) If this class method returns YES, you can start location services as planned. If it returns NO and you attempt to start location services anyway, the system prompts the user to confirm whether location services should be reenabled. Given that location services are very likely to be disabled on purpose, the user might not welcome this prompt.

like image 29
sosborn Avatar answered Dec 28 '22 06:12

sosborn