简体   繁体   English

没有NSApplication实例的Mac OS X应用程序是否可以?

[英]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". 在Info.plist中,我有一个键“Application is background only”,其值为“Yes”。 Most of the code is in C++. 大多数代码都是用C ++编写的。

The usual last line 通常的最后一行

return NSApplicationMain(argc, argv);

in main() is removed. 在main()中删除。 Instead main starts some thread(s), blocks and waits on some condition to exit. 相反,main会启动一些线程,阻塞并在某些条件下等待退出。

Yes it is OK. 是的,没关系。 NSApplication is declared in AppKit so it is used only in GUI apps. NSApplication在AppKit中声明,因此仅在GUI应用程序中使用。 An app can use Foundation, which does not require NSApplication. 应用程序可以使用Foundation,它不需要NSApplication。

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. 你可以拥有一个没有它的进程(通俗地说是一个应用程序),它可以在Unix方面正常工作,并且就像任何其他无头进程一样。

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. 你不能拥有的是一个完整的Cocoa应用程序意义上的应用程序,因为NSApplication (或子类)的实例不仅仅是你的应用程序的一部分,在非常真实的意义上,主应用程序对象应用程序。 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. 阅读Info.plist,挂钩到Cocoa应用程序系统,Applescript系统等等都是由NSApplicationMain()完成的,这使得它成为资本A应用程序的要求。

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); 如果您希望程序的行为类似于应用程序并与Cocoa方面进行交互,请return NSApplicationMain(argc, argv); is the wait to end main() . 是等待结束main()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM