简体   繁体   English

NSApp是否终止:id已弃用?

[英]Is NSApp terminate:id deprecated?

I have been searching for how to terminate my application programmatically. 我一直在寻找如何以编程方式终止我的应用程序。 I found in many topics people using NSApp terminate:id . 我在许多主题中发现使用NSApp terminate:id

In Xcode terminate:id is crossed. 在Xcode中terminate:id被越过。 Is this method deprecated ? 这种方法是否已被弃用? Should I use it to terminate my application ? 我应该用它来终止我的申请吗? If no which is the right way to do it ? 如果没有哪个是正确的方法呢?

Update: Picture of what i mean when I say that it's crossed: 更新:当我说它越过时我的意思的图片: 在此输入图像描述

I don't see that terminate is deprecated. 我没有看到terminate被弃用。 A possible cause for the compiler warning might be that in 编译器警告的可能原因可能是

[NSApp terminate:sender]

NSApp returns a general id , so that the compiler does not know which terminate message is actually meant. NSApp返回一般id ,因此编译器不知道实际意味着哪个terminate消息。 An indeed, if I use "Jump to Definition", Xcode jumps to 确实,如果我使用“跳转到定义”,Xcode会跳转到

@protocol NSInputServiceProvider
...
- (void) terminate:(id)sender NS_DEPRECATED_MAC(10_0, 10_6);

But if you use the equivalent code 但是如果你使用等效的代码

[[NSApplication sharedApplication] terminate:sender];

then the compiler warning goes away. 然后编译器警告就消失了。

Nope, not deprecated : 不,不要弃用


terminate: 终止:

Terminates the receiver. 终止接收器。

- (void)terminate:(id)sender

Parameters 参数

sender 寄件人

Typically, this parameter contains the object that initiated the termination request. 通常,此参数包含启动终止请求的对象。

Discussion 讨论

This method is typically invoked when the user chooses Quit or Exit from the application's menu. 当用户从应用程序菜单中选择退出或退出时,通常会调用此方法。

When invoked, this method performs several steps to process the termination request. 调用时,此方法执行几个步骤来处理终止请求。 First, it asks the application's document controller (if one exists) to save any unsaved changes in its documents. 首先,它询问应用程序的文档控制器(如果存在)以保存其文档中未保存的任何更改。 During this process, the document controller can cancel termination in response to input from the user. 在此过程中,文档控制器可以响应用户的输入取消终止。 If the document controller does not cancel the operation, this method then calls the delegate's applicationShouldTerminate: method. 如果文档控制器未取消操作,则此方法将调用委托的applicationShouldTerminate:方法。 If applicationShouldTerminate: returns NSTerminateCancel , the termination process is aborted and control is handed back to the main event loop. 如果applicationShouldTerminate:返回NSTerminateCancel ,则终止进程中止并将控制权交还给主事件循环。 If the method returns NSTerminateLater , the application runs its run loop in the NSModalPanelRunLoopMode mode until the replyToApplicationShouldTerminate: method is called with the value YES or NO . 如果该方法返回NSTerminateLater ,则应用程序在NSModalPanelRunLoopMode模式下运行其运行循环,直到使用值YESNO调用replyToApplicationShouldTerminate:方法。 If the applicationShouldTerminate: method returns NSTerminateNow , this method posts a NSApplicationWillTerminateNotification notification to the default notification center. 如果applicationShouldTerminate:方法返回NSTerminateNow ,则此方法NSTerminateNow NSApplicationWillTerminateNotification通知发布到默认通知中心。

Do not bother to put final cleanup code in your application's main() function—it will never be executed. 不要费心将最终的清理代码放在应用程序的main()函数中 - 它永远不会被执行。 If cleanup is necessary, perform that cleanup in the delegate's applicationWillTerminate: method. 如果需要清理,请在委托的applicationWillTerminate:方法中执行清理。

Availability 可用性

Available in OS X v10.0 and later. 适用于OS X v10.0及更高版本。

See Also 也可以看看

  • – run
  • – stop:
  • – applicationShouldTerminate: (NSApplicationDelegate) – applicationShouldTerminate: (NSApplicationDelegate)
  • – applicationWillTerminate: (NSApplicationDelegate) – applicationWillTerminate: (NSApplicationDelegate)
  • – replyToApplicationShouldTerminate:
  • NSApplicationWillTerminateNotification

Related Sample Code 相关示例代码

  • BlastApp BlastApp
  • PreLoginAgents PreLoginAgents

Declared In 宣告进入

NSApplication.h NSApplication.h

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

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