MAC:NSUserNotification

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)