How to make a running application on macos to float above other apps? - swift

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.

Related

Swift MacOS - Is there a way to block access(stop focus) to background apps when my app is opened?

I'm fairly new to Mac Development and now I'm developing a Swift application for desktop. The application consist of a window, which has a webview in it. Is there any possiblity that when my window opens it always stays at top, and you cannot click on any other windows bellow it.
For now I have made it this far with my code:
func applicationWillHide(_ notification: Notification) {
NSApplication.shared().activate(ignoringOtherApps: true)
}
func applicationDidResignActive(_ notification: Notification) {
NSApplication.shared().activate(ignoringOtherApps: true)
}
I'm using applicationWillHide and applicationDidResignActive to bring the window back to the top when a user clicks outside of it, but its still possible to focus on background apps, although they are not at the top. Can this "stealing" of focus somehow be disabled?

How to bring another cocoa application window to front

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.

Android Application: Returning to the activity where you stopped

I've been making a simple android app here, but i'm stuck with a problem. The app is composed of 1 splash(that is the main activity) and 4 other activities(one of them is used to go to the other 3). Whenever i exit my application and resume it with the process manager, it opens the activity i stopped at. But, when i resume it by clicking on the icon, it goes back to the splash activity. Is there any way to make it always go to where i stopped? Any flag or something i can set on the manifest?
This is an Android bug. The standard behaviour is to return to your application (in the same state as when you left) when launching it from the HOME screen. However, if you started your application for the first time from the installer, this gets broken.
To check if you are seeing this behaviour, go to the Settings->Applications and force close your application. Now go to the HOME screen and start your application. Use your application for a bit. Now press the HOME button to return to the HOME screen and launch your application again by clicking on the icon. It should return to your application exactly the way you left it.
See https://stackoverflow.com/a/16447508/769265 for more information and other links to this long-standing and nasty Android bug.

Application does not run in background mode

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.

ios app dosnt work when testing on a test device

When I build the application to the testing phone everything works fine. If i then press the home button go back to the main screen then run the app , again everything works fine.
However if I quit the app to the home screen then close the application from running in the background and then try to run the app again from the main icon, it wont run it just goes to black screen and stops the phone from working or itll load the main view and none of the buttons work.. the only way to fix the phone so its usable again is to lock it and turn the device on again..
has anyone suffered this same issue before?
Sometimes the bootstrap server seems to get confused when you hit the home button and return to the app. If you are testing multi-tasking/background behavior, try the following process:
Build and run from Xcode.
Disconnect your device (your app will quit).
Now, truly quit the app by double tapping the home button and holding down on the app icon.
Finally, reopen the app and test for multi-tasking/backgrounding behavior (your won't get console messages however).