MAC:NSUserNotification

作者: L柠_檬 | 来源:发表于2016-08-19 15:45 被阅读140次
    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

      本文链接:https://www.haomeiwen.com/subject/cqmbsttx.html