mahendra230668
mahendra230668

Reputation: 105

Is it OK to have Mac OS X application without an NSApplication instance?

In the Info.plist, I have one key "Application is background only" and its value is "Yes". Most of the code is in C++.

The usual last line

return NSApplicationMain(argc, argv);

in main() is removed. Instead main starts some thread(s), blocks and waits on some condition to exit.

Upvotes: 3

Views: 647

Answers (2)

Williham Totland
Williham Totland

Reputation: 28999

Yes and no.

You can have a process (colloquially an application) without it, and it will work just fine with the Unix side of things, and behave just like any other headless process.

What you cannot have is an Application in the sense of a full-fledged Cocoa Application, because an instance of NSApplication (or a subclass) isn't just a part of your application, in a very real sense the main application object is the application. Things like reading the Info.plist, hooking into the Cocoa Application System, Applescript System, and so on is all done by NSApplicationMain(), making it a requirement of a capital-A Application.

It is possible you could set some of these things up yourself, but I don't know of any ways to do so, and even if I did, I would not recommend it. If you want your program to behave like an application and interact with the Cocoa side of things, return NSApplicationMain(argc, argv); is the wait to end main() .

Upvotes: 1

SteffX
SteffX

Reputation: 167

Yes it is OK. NSApplication is declared in AppKit so it is used only in GUI apps. An app can use Foundation, which does not require NSApplication.

Upvotes: 1

Related Questions