gma*_*man 1 c++ macos alert objective-c
我正在尝试创建一个仅打开警报的简单应用。所以想象一下
int main(int argc, const char * argv[]) {
int result = SomeMagicAlertFunction("Hello World", "Yes", "No");
printf("User picked: %d¥n", result);
}
Run Code Online (Sandbox Code Playgroud)
我已经找到了一些有关的信息,NSAlert但是所有示例都是针对完整的OSX Apps的,其中包含一个应用程序包,例如
+-MyApp.app
|
+-Contents
|
+-MacOS
|
+-MyApp
Run Code Online (Sandbox Code Playgroud)
等等,但是我只想在命令行应用程序中发出警报。一个文件,而不是应用程序包。在OSX的C / C ++或Objective C中可能吗?我看到了一些有关的内容,NSRunAlertPanel但已在优胜美地删除,并说要使用NSAlert。
稍后找到答案
#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];
}
Run Code Online (Sandbox Code Playgroud)