1.1 初始化NSUserNotification
NSUserNotification *notification = [[NSUserNotification alloc] init];//创建通知中心
notification.title = title;
notification.subtitle = subtitle;
notification.informativeText = information;
// notification.contentImage = [NSImage imageNamed: @"ladybugThumb.jpg"];
//只有当用户设置为提示模式时,才会显示按钮
notification.hasActionButton = YES;
notification.actionButtonTitle = @"确定";
notification.otherButtonTitle = @"取消";
[[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:notification];
//设置通知的代理
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
//通知已经提交给通知中心
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNotification:(NSUserNotification *)notification
{
NSLog(@"收到通知");
}
//用户已经点击了通知
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
NSLog(@"用户点击");
}
//returen YES;强制显示(即不管通知是否过多)
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification
{
return YES;
}
MAC:NSUserNotification
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 目前通过源代码编译安装MacPorts,是唯一的在mac os x10.12 sierra上安装的方式 下载Mac...
- 这个一般是导出的时候会报的错。 1去开发者网站申请一个新的Distribution 2选择Ad Hoc 3重新导...
- 1、首先你必须有一台苹果电脑,在App store下载 苹果 OS X El Capitan 系统。大概6G多,下...
- 2015年的MacBook Pro(机械硬盘,8G内存),之前升级到Mac 10.11,但会经常的卡顿,所以一直使...