[英]Create alert / message box in command line OSX app
I'm trying to create a simple app that just opens an alert. 我正在尝试创建一个仅打开警报的简单应用。 So imagine this
所以想象一下
int main(int argc, const char * argv[]) {
int result = SomeMagicAlertFunction("Hello World", "Yes", "No");
printf("User picked: %d¥n", result);
}
I've found some info about NSAlert
but all the examples are for full OSX Apps, the kind with an app package as in 我已经找到了有关
NSAlert
一些信息,但所有示例均适用于完整的OSX Apps,该类带有如下所示的应用程序包
+-MyApp.app
|
+-Contents
|
+-MacOS
|
+-MyApp
etc, but I just want an alert in a command line app. 等等,但是我只想在命令行应用程序中发出警报。 One file, not an app package.
一个文件,而不是应用程序包。 Is that possible in OSX in either C/C++ or Objective C?
在OSX的C / C ++或Objective C中可能吗? I saw something about
NSRunAlertPanel
but that's been removed in Yosemite and says to use NSAlert
. 我看到了有关
NSRunAlertPanel
但是在优胜美地中已删除,并说要使用NSAlert
。
Found an answer moments later 稍后找到答案
#import <Cocoa/Cocoa.h>
void SomeMagicAlertFunction(void) {
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Delete the record?"];
[alert setInformativeText:@"Deleted records cannot be restored."];
[alert setAlertStyle:NSWarningAlertStyle];
if ([alert runModal] == NSAlertFirstButtonReturn) {
}
//[alert release];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.