I have developed a Mac OS app. There is a main window app and a menubar helper app in the same bundle.
There is a menu item of helper app called "Show main app". The helper app should launch the main app if it is not launched after i click the menu item. And the helper app should bring the main app to front if it is hidden in dock or its main window is closed.
I know how to launch the main app. But I have no idea how to implement the re-active function. I used the code like below.
let apps = NSRunningApplication.runningApplications(withBundleIdentifier: "com.xxx.yyy")
if let mainApp = apps.first {
mainApp.activate(options: [ .activateIgnoringOtherApps ])
}
It seems activate method does nothing when the main app is just launched and hide in dock. I noticed the main app is actually activated, because the main menu bar has changed to main app's main menu. But the "applicationShouldHandleReopen" method of its AppDelegate class is not called. So the main window can't be ordered front.
How can I make it works?
No matter the target application is launched or not, just call
NSWorkspace.shared().launchApplication("xxxx")
It works.
Related
I am making an application that can set a running application window to float above other apps so that if you click outside of the app's window, its window will still remain on the screen.
I have tried to use app.activate(options: NSApplication.ActivationOptions.activateIgnoringOtherApps) where app is the frontmost running application set by app = NSWorkspace.shared.frontmostApplication, but this method only shows the window and when you click outside the app it hides again.
func setAppFloating() {
let app = NSWorkspace.shared.frontmostApplication
app?.activate(options: NSApplication.ActivationOptions.activateIgnoringOtherApps)
}
I want to set the window of the running application to Floating so that when you click outside the window, the app should still remain visible above other apps.
Right now, I have an application with a single map view. What should I do to stop the app from retrieving new location updates once I hit the home button. My goal is to make that arrow next to the battery symbol disappear when on the main menu page. The app will launch again when the user brings it back to the foreground. This is what I have so far, but it's not working.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
exit(0);
}
What you have should work (in fact, I have used it once for debugging purposes).
However, you should not do that, despite the fact that it works. Simply set the UIApplicationExitsOnSuspend key in the Info.plist file of your application to true.
I have set "Application does not run in background mode" property key to YES and when I hit the home button it only puts the application into background mode when I click home button twice the app is still running in background and when I relaunch the app the application will enter foreground method is called . I have a setting bundle that creates tabs for UITabBarcontroller and I want the app to quit as it need to run the setup method to work out which tabs to show . I tried to use application will enter foreground to remove view controllers from the tabbar controller by reading the settings bundle and it works but the application will enter foreground method is no good as I can not re-add the view controllers I removed if the settings are changed back again so my only option is to quit the app and the application did launch with options method alloc and init all view controller b reading the setting bundle first . Is there any other way to quit the app
The fact that your app's icon is listed once you double press the Home button is not indicative that it is running. At best, it indicates which apps the user used last.
"Running in the background" and "loaded into memory, ready to resume" are not the same thing. It's a bit similar to how you can shutdown a computer (it's not processing anything), and if put a computer to 'sleep', it's still not processing… but the state of the computer is kept.
I would invite you to read the suspended and background states : App States and Multitasking.
I am using x-code 4 and any time I start a "view based application" (say "Test") IB opens up and creates 6 files. 1)TestAppDelicate.h 2)TestAppDelicate.m 3)MainWindow.xib 4)TestViewController.h 5)TestViewController.m 6)TestViewController.xib
Now the Main Interface is set to MainWindow yet when I run the app it always starts up the TestViewController.xib not mainwindow.
The problem is If I change from iPhone to Universal app it creates a MainWindow-ipad.xib that is unusable. How do I get it to use mainwindow?
Is this a bug? Or am I doing something wrong or am I uninformed?
The MainWindow.xib creates the root window and sets it's view controller to the TestViewController. TestViewController's contents are created in the TestViewController.xib.
In other words, you ARE using the main window.
What does double-tapping on the home button exactly do?
Does it list the applications running in background, OR
Does it list recently used applications?
I've implemented the "Application does not run in background" in my Info.plist file. In spite of this my application shows on double tapping the home button !! Yes I have tried a clean build.
It shows all recently-used apps, not just the multi-tasking ones. If you try to tap your app now, it will start exactly like it was first launched, displaying the launch image first before initializing (calling application:didFinishLaunchingWithOptions: and sending the relevant notifications).