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.
Related
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.
As we know, at windows 8 if user is at start screen or another store app (metro app) UI, the dialog at the desktop won't be visible to user. We are adding some toast notification capability at our application by following Sending toast notifications from desktop apps sample. I am able to get it working. However if user is already at the desktop, we don't want to send out the toast notification. So it would mean that we need to be able to detect if user is current at desktop or not. Somehow I didn't find any API by searching on internet. Could someone let me know how to do so? Thanks very much.
A toast notification can't know in what context the user is located, so this is not possible.
I am not sure this can be done at all...
Background: I am constructing an in-house application which means it does not get into appstore so i am not limited by the appstore guidelines.
I have a dylib which loads before the main application. It is a kind of augmenting library for applications. I am using the constructor __attribute__ to load my stuff. In there i would like to put an alertview or any kind of popup which will receive a user/password question. If the password is correct than the user is allowed to continue into the original application.
Since this is in the dylib i do not yet have a UIApplication and i do not want to interfere in the original application or sources.
Suggestions, tips are welcome...
Thanks.
This is how i've done very similar thing in my application:
0) Intercept applicationDidFinishLaunching message, add your own code, run original implementation.
1) Make opaque fullscrean UIWindow (for example, black).
2) Set its windowLevel to UIWindowLevelAlert + 1 So it hides every other window in app.
3) Add fields for user and password to this UIWindow.
I'm pretty sure you can't show a UIAlertView without having initialized the UIApplication and UIWindow instance.
Only the iOS itself can show alerts outside the application, for example when it asks for permissions or in case of iTunes or game center login ...
As a workaround you can:
make a login view inside the application
create a web application for the login process. The web app could launch the native app with a custom URL scheme and pass parameters like 'user' and 'password' to the app.
You should create a View for the Login then if you pass the login you can go on using the app otherwise you just make the app shut itself.
You could start a thread when loading your dylib and make it listen for your UIApplication to become available, then display the alert on the main thread.
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.
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.