Questions tagged [nsapplication-delegate]
33 questions
2
votes
0 answers
How to be notified when a non-visible Mac OSX app is closing down? -- applicationWillTerminate() not called
I have a Mac app whose applicationWillTerminate:(NSNotification *) handler is not called when the app closes down. There is some c++ memory cleanup code that must be called if the program is shut down, so I need some way to do this.
The reason it…

Alyoshak
- 2,696
- 10
- 43
- 70
2
votes
0 answers
How to initialize a NSDocument after calling LSLaunchFSRefSpec?
I am working on a document-based application. If I execute this app from the Finder it runs like expected: First the NSApplicationDelegate applicationDidFinishLaunching method is executed. Then the NSPersistentDocument initialization is done. After…

user2581362
- 21
- 1
2
votes
1 answer
Order of NSApplication delegate calls
I'm noticing something strange in my NSApplication delegate callbacks. When I start the app with debugger attached, I see what I expect: applicationDidFinishLaunching: is called first, then applicationDidBecomeActive:
When I run the app without the…

Z S
- 7,039
- 12
- 53
- 105
2
votes
3 answers
Why not enforce strict singleton application delegate object to use in NIBs?
I just ran myself round in circles, all coming down to having instantiated an app delegate object in a secondary NIB that wasn't the NSMainNibFile. Amazing how having two app delegates kicking around means you have separate…

stevesliva
- 5,351
- 1
- 16
- 39
2
votes
4 answers
Best place to clean-up App global resources?
STOP PRESS OK before you see the word retainCount in the following question, please skip to the EDIT at the bottom where I have stated that I have stopped using it.
My Cocoa App, which uses MRR, creates many global resources, which I am loading in…

trojanfoe
- 120,358
- 21
- 212
- 242
2
votes
1 answer
How to handle Cocoa application termination properly?
So, here's my case :
I'm developing a NON-standard document-based application and I want to handle the scenario of aborting the termination when there still are unsaved changes in any of the documents.
My initial idea is :
User tries to quit the…

Dr.Kameleon
- 22,532
- 20
- 115
- 223
1
vote
1 answer
Mac Widgets: NSApplication openURLs not called from widget
I am working on a widget for my existing Mac app. The problem I am running into is that when I add a Link from the widget to the main app, the method - (void) application: (NSApplication *)application openURLs:(NSArray *)urls isn't called…

Z S
- 7,039
- 12
- 53
- 105
1
vote
1 answer
At launch, prevent a document-based app to reopen an unsaved-unedited-empty document that was opened when quit
In a simple rtf editor —based on NSDocument subclass—, when app starts, it creates an untitled file. This a desirable behaviour. But if I quit the app with this opened, unedited and unsaved document (empty!), the application will restore this…

Denis
- 775
- 7
- 22
1
vote
1 answer
How to implement NSApplicationDelegate protocol in glfw application
I am currently programming an application using glfw in MacOS X. My only problem is that the application doesn't use an AppDelegate, but does all the initialization in the main.cpp file like a command line utility. I specifically want to implement…

Andres Bucci
- 947
- 1
- 9
- 37
1
vote
1 answer
How to prevent logout from app running as agent
The sample menu bar app is a agent as its LSUIElement is TRUE.
I want to prevent logout on certain conditions.
I tried with - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender.
But I never receive this message when…

sac
- 890
- 6
- 19
1
vote
0 answers
NSApplication applicationShouldTerminate called before applicationDidFinishLaunching
I've got a strange problem: got a singleton which is initialized in applicationDidFinishLaunching of AppDelegate, but in some cases I receive crash reports with EXC_CRASH (SIGSEGV) and a stack trace like this:
0 com.name.myapp …

silvansky
- 2,426
- 2
- 19
- 20
0
votes
0 answers
Correct way to handle applicationShouldTerminate when red close button is clicked in my macOS GUI app
I have a SwiftUI app that allows only a single window. When the user tries to close the app, I want to check for some condition, show a warning and ask the user if they still want to close, and if not, then prevent it. Here's what I have so…

c00000fd
- 20,994
- 29
- 177
- 400
0
votes
0 answers
How to toggle menu bar popover from a method outside of AppDelegate in Swift?
I am new to Swift UI and currently working on a menu bar app for MacOS.
I created a AppDelegate in which there is a method which toggles the menu bar popover when the icon in the menu bar is clicked - This is all working perfectly.
Now I want to use…

dev1999
- 1
0
votes
1 answer
Make one last change to NSDocument before app terminates/window closes?
I have a basic NSDocument-based app. I need to make one last change to the document when:
The user closes the document's window
The user terminates the app
Why?
The document window contains an NSTextField. Usually text entered into this text field…

Mark
- 6,647
- 1
- 45
- 88
0
votes
1 answer
Get name of file that launched an app in ViewController class?
I implemented the NSApplicationDelegate method func application(_ sender: NSApplication, openFile filename: String) -> Bool to get the name of the file that is double-clicked to launch my macOS app (Swift 4.x). However, it appears that this method…

Kenny
- 429
- 6
- 22