nsapplication

Stopping the NSApplication main event loop

限于喜欢 提交于 2021-01-27 19:20:02
问题 I have an application consisting of the following single .m file: #import <Cocoa/Cocoa.h> int main(int argc, char* argv[]) { [[[NSThread alloc] initWithBlock: ^{ sleep(2); dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"Stop"); [[NSApplication sharedApplication] stop:nil]; }); }] start]; [[NSApplication sharedApplication] run]; NSLog(@"Run finished"); return 0; } According to the developer documentation, stop should stop the main loop ( run ), but it doesn't (at least not on OS X 10.12

How to check Mac OS X version at runtime

筅森魡賤 提交于 2020-07-15 07:39:43
问题 I am using below code to check OS X version at runtime. if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_10) { /* On a 10.10.x or earlier system */ } But this condition return false on 10.10.4 OS X. I am using Xcode 6.3.2. According to AppKit Release Notes for OS X v10.11, It should work. if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_9) { /* On a 10.9.x or earlier system */ } else if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_10) { /* On a 10.10 - 10.10

NSApplication responder chain for arrow keys

℡╲_俬逩灬. 提交于 2020-05-24 05:33:08
问题 I have an NSTextField in my window and 4 menu items with key equivalents ← ↑ → ↓ . When the text field is selected and I press an arrow key, I would expect the cursor to move in the text field but instead the corresponding menu item action is performed. So there has to be an issue in the responder chain. To figure out what's wrong I've watched WWDC 2010 Session 145 – Key Event Handling in Cocoa Applications mentioned in this NSMenuItem KeyEquivalent space " " bug thread. The event flow for

Not displaying Mouse cursor

╄→гoц情女王★ 提交于 2020-01-02 03:35:11
问题 I am developing Mac desktop application, where i am capturing the screen using CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionAll, kCGNullWindowID, kCGWindowImageDefault); and display the screen shot, The problem is, i am expecting it should show the mouse cursor too, but its not showing, do i need to enable any settings for that ? I tried following before calling this function CGDisplayShowCursor(kCGDirectMainDisplay);

What exactly should I pass to -[NSApp activateIgnoringOtherApps:] to get my application to start “naturally” in comparison to most other OS X apps?

≡放荡痞女 提交于 2019-12-22 10:52:36
问题 When I learned how to start NSApplications on my own, the code I used (based on here and here) did [NSApp activateIgnoringOtherApps:YES]; which forces the app to the front at startup. I'd like to know what most other apps do. I want to be able to run programs both directly from the binary and from an app bundle, and I'm not using Xcode to build this (raw building). So I'd rather this act naturally, so to speak. The docs do say Finder issues NO , but... why Finder? Isn't this a method that's

Cocoa Dock fires NSApplicationDidChangeScreenParametersNotification

筅森魡賤 提交于 2019-12-11 14:41:41
问题 When changing the dock position Cocoa is firing a NSApplicationDidChangeScreenParametersNotification: The problem is that as for Apple Docs, it should be raised only when Posted when the configuration of the displays attached to the computer is changed. The configuration change can be made either programmatically or when the user changes settings in the Displays control panel. The notification object is sharedApplication. This notification does not contain a userInfo dictionary. So if you

Cocoa: NSApp beginSheet sets the application delegate?

那年仲夏 提交于 2019-12-11 01:21:40
问题 I am trying to display a custom sheet in my application, but I think I am doing something wrong. While everything seems to be working just fine, I have a rather odd side-effect. (which took hours to figure out). It turns out that everytime I display a sheet in my application, the Application delegate gets set to the instance of the sheet, thus my Controller gets unset as the delegate causing all sorts of problems. I've created a NIB file which I called FailureSheet.xib. I laid out my

Get NSWindow from kCGWindowNumber

帅比萌擦擦* 提交于 2019-12-10 12:44:46
问题 From k CGWindowNumber , how do I get NSWindow ref. I tried using: [NSApp windowWithWindowNumber:windowNumber] but I always get a null value. I need to get the NSWindow to apply [window setlevel:NSFloatingWindowLevel] , that I have set the always on top of a given window. Does anyone know how to solve this problem or has any alternative solution? Thanks for the answer, but this is not the solution, I had already tried but it does not work, actually I did a test , I tried the following code:

Cocoa: Call App Delegate Method from another Class

狂风中的少年 提交于 2019-12-08 00:47:55
问题 I'm currently trying to get the path of a file from a drag and drop operation inside of a custom view, and then pass that path to my app delegate. I'm currently using the following: - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender { NSPasteboard *pb = [sender draggingPasteboard]; NSString *type = [pb availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]; NSArray *array = [[pb stringForType:type] propertyList]; //access the app delegate NSApplication *myApplication;

Any good way to set the exit status of a Cocoa application?

浪尽此生 提交于 2019-12-07 09:28:21
问题 I have a Cocoa app which interacts with a server and displays a GUI. If there is a fatal error, I display an alert and exit. I'd like to set the exit status to a non-zero value to reflect that an error occurred, for ease of interaction with some other UNIX based tools. Unfortunately I've been unable to find a good way to do so - NSApplication doesn't seem to have any way to set an exit status. At the moment, I've subclassed NSApplication and added an exitStatus ivar (which I set in my app