Macos 在控制台hello world应用程序中运行代码时未显示NSNotification
我尝试从控制台应用程序发送本机通知,但在运行时没有显示任何内容。我是否遗漏了推送通知所需的内容Macos 在控制台hello world应用程序中运行代码时未显示NSNotification,macos,cocoa,notifications,toast,nsnotifications,Macos,Cocoa,Notifications,Toast,Nsnotifications,我尝试从控制台应用程序发送本机通知,但在运行时没有显示任何内容。我是否遗漏了推送通知所需的内容 #import <Cocoa/Cocoa.h> #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSUserNotification* notification = [[NSUserNotification al
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSUserNotification* notification = [[NSUserNotification alloc] init];
notification.identifier = @"unique-id";
notification.title = @"Hello!!!";
notification.subtitle = @"How are you?";
notification.informativeText = @"This is a test??????";
notification.soundName = NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
// insert code here...
NSLog(@"Hello, World!");
}
return 0;
}
#导入
#进口
int main(int argc,const char*argv[]{
@自动释放池{
NSUserNotification*通知=[[NSUserNotification alloc]init];
notification.identifier=@“唯一id”;
notification.title=@“你好!!!”;
notification.subtitle=@“你好吗?”;
notification.informativeText=@“这是一个测试”;
notification.soundName=NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter]传递通知:通知];
//在这里插入代码。。。
NSLog(@“你好,世界!”);
}
返回0;
}
来自NSUserNotificationCenter的文档:
当到达用户通知的传递日期时,或者
手动交付时,通知中心可能会显示
通知用户。用户通知中心保留
决定是否向用户提交已交付的用户通知的权利
用户。例如,如果应用程序
已位于最前面(代理可以覆盖此操作)。这个
应用程序可以通过检查
已传递用户通知的presented属性
您应该检查以下内容,以确定它们是否正确:
// make sure the notification was delivered
[[[NSUerNotificationCenter defaultUserNotificationCenter] deliveredNotifications] containsObject:notification]
// see if the notification was presented
notification.presented