8 Replies
      Latest reply: Jan 12, 2017 12:56 AM by jljl789@icloud.comjljl789@iclo RSS
      imneo Level 1 Level 1 (0 points)

        Hope my scenario is not weird. Here is the description:

        1. User runs my app.

        2. User hides my app completely (all windows are hidden) so that he/she has no way to accessing the app. (Dont' ask why, user requested this feature and I want to implement it.)

        3. Now user rerun my app and I want to use XPC to tell the running instance to show itself.

         

        It sounds very reasonable and I have done most of code. But it is blocked by macOS the system. It seems macOS controls only one instnace of an app can be running at the same time; second try to run the same app (in /Applications) simply does nothing - the app code does not even get executed so that my code in main.m won't have the change to communicate with XPC.

         

        I believe there must be a way to overcome this. Any suggestions will be appreciated. Thanks and Merry Xmas!

        • Re: How to activate app's running instance
          pmills Level 2 Level 2 (35 points)

          I would expect your running app to get app delegate callbacks for applicationDidUnhide or applicationDidBecomeActive (or both).  Do you implement those?

          • Re: How to activate app's running instance
            eskimo Apple Staff Apple Staff (6,665 points)

            2. User hides my app completely (all windows are hidden) so that he/she has no way to accessing the app.

            Does your app show up in the Dock?

            Share and Enjoy

            Quinn “The Eskimo!”
            Apple Developer Relations, Developer Technical Support, Core OS/Hardware
            let myEmail = "eskimo" + "1" + "@apple.com"

              • Re: How to activate app's running instance
                imneo Level 1 Level 1 (0 points)

                Oh, I forgot to mention this. I hide all windows completely from dock using a method like below:

                + (BOOL)hideWindowFromDock:(NSWindow *)window
                {
                    if ([NSApp activationPolicy] != NSApplicationActivationPolicyProhibited)
                    {
                        [NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited];
                    }
                    [window setIsVisible:NO];
                    return YES;
                }
                
                
              • Re: How to activate app's running instance
                KMT Level 8 Level 8 (8,020 points)

                     >User hides my app completely (all windows are hidden) so that he/she has no way to accessing the app.

                 

                Even via cmd-tab? Or Apple logo/recent items?

                  • Re: How to activate app's running instance
                    imneo Level 1 Level 1 (0 points)

                    Cmd-TAB will not show my app because I hide windows by setting NSApplicationActivationPolicyProhibited (hiding from dock).


                    When I said 'no way to access my app' I mean by means of interactive UI, not recent items. The user is always able to 'access' my app in /Applications. But that's not the key to my problem.

                     

                    Maybe my English is not good engough to express that I want. But anyway I wil l put it in another way. What I want is simple - I want to bring back app's UI after user requested hiding all of them.