Im using the following code to hide all the running applications whose activationPolicy == .regular and if the bundle identifier is different from my app.
NSWorkspace.shared.runningApplications
.filter { runningApps.contains($0.bundleIdentifier) }
.forEach { item in
item.hide()
}
Right after hiding them some just automatically unhide, apps that usually have a search bar or first responder textview like telegram, finder, messages. It's random and sometimes it reappears, sometimes not...
I also tried with NSWorkspace.shared.hideOtherApplications() but it does the same
macOS 10.14.3
Any idea on what should I do before hiding?
Related
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?
I am am writing my XCUITests for my app, and currently struggling in finding the best solutions to dismiss my apps alerts. I have two sets of alerts, one is a notifications alert which pops up at the beginning of a fresh install, the second is a location alert when I navigate to the nearby tab on my app after a fresh install. I have tried using
let alert = app.alerts["\u{201c}VoucherCodes\u{201d} Would Like to Send You Notifcations"].collectionViews.buttons["OK"]
if alert.exists{
alert.tap()
}
but no success, I have also tried using a systemAlertMonitorTokenin my my setUp()
systemAlertMonitorToken = addUIInterruptionMonitorWithDescription(systemAlertHandlerDescription) { (alert) -> Bool in
if alert.buttons.matchingIdentifier("OK").count > 0 {
alert.buttons["OK"].tap()
return true
} else {
return false
}
}
Does anyone have any suggestions or point out where I am going wrong so I can fix this, thanks.
You might find these two questions and their answers to be illuminating:
Xcode 7 UI Testing: Dismiss Push and Location alerts
Xcode 7 UI Testing: how to dismiss a series of system alerts in code
Starting with a blank OS X application project, I add the following code to applicationDidFinishLaunching.
func applicationDidFinishLaunching(aNotification: NSNotification) {
let app = NSApplication.sharedApplication()
guard let window = app.keyWindow else {
fatalError("No keyWindow\n")
}
print(window)
}
At launch I hit the error case because my local window variable is nil. Yet when I show the contents of the app variable, I see a valid value for _keyWindow. Also notice that the blank GUI Window is being displayed on the screen next to the stack dump.
Why does the keyWindow: NSWindow? property return nil in this case?
Thanks
NSApplication's keyWindow property will be nil whenever the app is not active, since no window is focused for keyboard events. You can't rely on it being active when it finished launching because the user may have activated some other app between when they launched your and when it finished launching, and Cocoa is designed to not steal focus.
To some extent, you may be seeing that happen more when launching from Xcode because app activation is a bit strange in that case. But, still, you must not write your applicationDidFinishLaunching() method to assume that your app is active.
What you're seeing in terms of the app's _keyWindow instance variable is, of course, an implementation detail. One can't be certain about what it signifies and you definitely should not rely on it. However, I believe it's basically the app's "latent" key window. It's the window that will be made key again when the app is activated (unless it is activated by clicking on another of its windows).
I am developing an iPhone app using Titanium Alloy.
My problem is that I would like to change the backgroundImage of rightNav button.
I am using the rightNav button as a Filter button. My Filter button is placed in a window which also has a table. Once the filter button is clicked a new window is opened where the user can make some selections. Once the selection is made, the table on the previous page is refreshed based on the selections made and I would like to change the backgroundImage of the rightNav button to show that some selections have been applied. But I am unable to do so.
My code :
if ((screenType === "parentWindow") {
$.rightNav.visible = true;
$.rightNav.backgroundImage = "/images/buttons/filterOff.png";
} else if ((screenType === "childWindow")) {
$.rightNav.visible = true;
$.rightNav.backgroundImage = "/images/buttons/filterOn.png";
}
The backgroundImage of the rightNav button is set first time and then it is not changed. I have tried to make it null and then set it again but it does not work.
Please help.
Other details :
Titanium Command-Line Interface, CLI version 4.0.0, Titanium SDK version 4.0.0.RC, Mac OS X 10.10
Thanks
Try using the image property .
I just finished my iPhone app and I want to make it Universal. I've read a few posts already but they're a bit old (2010 or so).
What I got:
Simple iPhone app, recently created (iOS 5 - Storyboard), with three screens.
My app represents a table with three cards that you can flip touching them. The user can input (on the second screen) text to be displayed on the cards.
When I created the project I checked "Universal" so I have two Storyboards. After that nothing else I did had to do with iPad (except for a line on my "contact support" email option where I used UIModalPresentationPageSheet).
What I'd like to accomplish:
Same app on the iPad: my application is so straightforward I don't have any use for split views or details. I just want the same objects and layout but with bigger and better graphics (table, cards, etc).
I like it because it'd make a great introduction-level migration.
I have no idea where to start. When I run the iPad simulator a white screen comes up and that's it.
Well this is done.
As with almost everything, this is pretty easy once you know what to do.
I'd say that for those cases like mine, where the UI doesn't change in more than sizes or (x,y) coordinates the process could be summarized like this:
Replicate every UI element on the iPad Storyboard (copy and paste will do) and adjust position and size as you see fit
Re-wire everything again. Every button, segue (you'll have to add the segue name again too), etc.
Verify within your code every place where your UI is affected (e.g. x,y coordinates), identify whether the app is running on an iPhone or iPad, and divide your code accordingly
If you have any localization on the application you'll have to update the new UI elements on the iPad Storyboard
Select the target for testing on the simulator and try it out
In order to identify in which device the app is running you can use the following:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//I'm running on the iPad
} else {
//I'm running on the iPhone
}
And that's it. Again, in a simple case like mine the reuse of code is absolute (100%), the new code you'll have to add is minimum (basically IF statements where needed), and the UI elements duplication is as easy as copy and paste.
I hope this is useful to someone else and if you have recommendations to improve this they're more than welcomed.
Open the Storyboard file in finder,Copy your iPhone-Storyboard and rename it Main-iPad.storyboard
Inside xCode, right click on the storyboard -> “open as” -> “Source Code”
Search for targetRuntime="iOS.CocoaTouch"and make it targetRuntime="iOS.CocoaTouch.iPad"
Now save everything and reopen Xcode -> the iPad-Storyboard contains the same as the iPhone-file but everyting could be disarranged you have to arrange it by your self.
Finally to get the iPad format also change the code in the MainStoryboard_iPad.storyboard from: to
Then go to your "StroryBoardEx-Info.plist" file,search for "Main nib file base name (iPad)" and make it "Main-iPad.storyboard"
If you just want to reuse your iphone storyboard, just go to your project settings. In TARGETS tab Info, there are rows 'Main storyboard file base name' and 'Main storyboard file base name (iPad)'. Just edit the iPad one to have the same value as the other. In my case I had to edit it as 'Main storyboard file base name (iPad)' with value 'MainStoryboard_iPhone'.