Getting results of location permission dialog - objective-c

I am doing this tutorial that would return the GPS coordinates. When I run the application on the iPhone, I am first presented with the UIAlertView asking permission to access my GPS coordinates.
I need to know from where this UIAlertView is thrown? Is it from the OS?
Can we capture this method? When the user clicks on "Allow" or "Don't allow", can I print his choice to the console?
How can I do this programatically? Is there an event for this?

This alert is shown by the OS. The usage of location-based API must be permitted by the user. You can ask the CLLocationManager for the current authorizationStatus and be notified when the status changes (delegate method will be called). Note that the user also can disable location services later in the settings app.

I assume you are using CLLocationManager. Your delegate will get locationManager:didChangeAuthorizationStatus when the applications ability to use the API changes.
Edit:
The first time your application attempts to use the service, the user will be prompted. If the user answers No, your application will not be able to use the service unless they go to Settings->General->Location Services and change the setting for your application.
If you query the API for status and are disallowed, you could put up your own pop-up and instruct the user on how to change the setting for your application.

Related

Custom view to allow location services

I want to be able to create my own view to allow location services from my iOS app. I've read here that it's possible to customise the description of the default iOS location services alert, but what I want is making my own view.
Is this possible?
Thanks!
No, it is not possible. All you can/should do is popping it at the right time. You should make sure that user is informed that permission is really needed, according to several researches (yes, citation needed :) ).
EDIT: it pops up when you first call start monitoring/updating location method from your CLLocationManager instance.
Since iOS8, you should call requestWhenInUseAuthorization or requestAlwaysAuthorization for it to pop up.
Here you can find some very good ideas about it.
Since you can not change the Apple Services Authorisations;
I would recommend you to create your custom view with "allow" & "dont allow" buttons. And than on "allow" pressed request apple permission witch will prompt the iOS or mac OS alert.
Though it seems not user-friendly. Apple users are used to this. Nobody will mind, and you will still show your own design. A lot of famous apps do that.

Provide an OSX Service Without Launching the App?

I have successfully implemented a "faceless service" (background-only app with .service extension) and get it to work (see this question), based on Apple's documentation and other tutorials on the web.
Now, I want to advertise a service from an existing, single-window GUI app that I have.
I have setup the Info.plist file of my app to advertise the service, and it gets installed when I build the app.
But when I invoke the service from the context menu in (say) TextEdit.app (my service colours the selected text based on a certain criterion), my app gets launched, main window and everything. To make things worse, I am right-clicking on a TextEdit window that is in a secondary monitor, so my app's main window appears for an instant in the secondary monitor, then quickly repositions into the main monitor (this might have something to do with my window-centering logic, but nevermind...).
I would like to provide the service (i.e., have the class that provides the service in my app
instantiated and execute its method in response to the request), without my app appearing on the Dock or showing its window and main menu.
Is this possible? Safari advertises "Search With Google", so it should be possible...
EDIT: Now that I think about it, "Search With Google" must launch Safari every time in order to work, so this remark does not apply.
Perhaps I can put some logic in -applicationWillFinishLaunching/-applicationDidFinishLaunching to determine if the app is being launched in response to a service, and skip creating the window(notice the lack of withOptions: in OSX)?
But still, that doesn't feel right.
It does have a lame version of withOptions: -- NSApplicationLaunchIsDefaultLaunchKey tells you if your application was launched to either:
open or print a file, to perform a Service action, if the app had saved state that will be restored, or if the app launch was in some other sense not a default launch
So in your applicationDidFinishLaunching you can see if that key is in the notification and set to NO. Unfortunately, the main way to tell that it is one of the possibilities other than the Service, you have to detect and record whether or not you also got an application:openFile:, etc.

Dimiss location service alert using code

I am using Core Location API for one my Cocoa application. With every application launch, it throws an alert asking for user permission for location services. I want to use the location services but with each application launch I do not want user to give permissions. Is there any way to dismiss this alert from code and still have the lat/long co-ordinates returned.
I did a bit of research on devforums for you and if you run your app outside of Xcode, it shouldn't ask you for authorization each and every time.

CLLocationManager "turn on location services..." alertview customization ios

I know that I can't change the title or the buttons for this alertview, but i've seen numerous apps that changed the message of the alert view
Something like this
Also, I have the Bump API in my app so everytime the popup shows, it says "Bump uses your location to help determine whom you are bumping." and I don't want that displayed when they first use my app.
Does anybody know how I can change the message or change bump's message?
Thanks
To change the message of the alert, use the "purpose" property of CLLocationManager. Check the docs: http://developer.apple.com/library/IOs/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html
I'm not sure how the Bump API works, but if you are just importing all the classes you need, you should be able to edit the location services message. Otherwise, one option would be to request location access before calling the Bump API's to get permission for your app. Once Bump checks, it will already have permission and skip presenting its own.

Confirm user's selection of "Don't Allow" location services

I am using location services in my app. Initially the app asks the user to allow finding the current location. If the user says "Don't Allow", can I show one more alert to confirm that choice? Then, if the user says "Allow" in that second dialogue, can the app get the current location?
No you can't, it is managed by the the system.
You can/should check if the user allowing you app to get the current location.
Because you can change this in the settings app
Check can be done like this:
if (![CLLocationManager locationServicesEnabled]) {
// location can not be retrieved.
}
i think..................
its a not possible beacuse its a default setting of iPhone ....
if u get answer please reply ....in this page......
but u change the setting of iphone, go to setting icon , go to general icon , go to current location and on this button...
sry for poor english
The question is who is showing the second message.
If it's CoreLocation that is showing the message than the last answer is the one that counts - so if it was "allow" then you can.
However - if after the "Disallow" you show your own custom message - the answer there has no affect.
It must come from CoreLocation