Modify Info.plist to set "Application is agent (UIElement)" at run time

Let's say I need to give the user the opportunity to select the settings panel, whether to use this application as β€œstandard” (with a dock icon and menu) or as an agent application (only from the status bar menu).

I think I need to programmatically change the "Info.plist" application at run time by changing the "Application - Agent" parameter to YES / NO.

Is it correct?

PS You can find this behavior in Sparrow.

+6
source share
1 answer

You should not modify the Info.plist application Info.plist (or anything in your application) at run time. This is bad practice and you will also break your application if it is signed with code. This is more important now, since all applications in the application store must be signed with code.

It is best to use the TransformProcessType() Application Services function to move the application from the background to the foreground application.

First set the LSUIElement key in the Info.plist application to YES , and then check the default startup for the user to determine whether your application should work as an agent or not:

 #import <ApplicationServices/ApplicationServices.h> @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)notification { if (![[NSUserDefaults standardUserDefaults] boolForKey:@"LaunchAsAgentApp"]) { ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToForegroundApplication); SetFrontProcess(&psn); } } @end 

Make sure you remember to add the application infrastructure to your project.

+13
source

Source: https://habr.com/ru/post/894645/


All Articles