首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >didActivateNotification没有响应NSUserNotification

didActivateNotification没有响应NSUserNotification
EN

Stack Overflow用户
提问于 2012-11-03 08:13:06
回答 1查看 1.4K关注 0票数 1

我正在努力让osx原生通知正常工作。我可以创建通知,但不能让didActivateNotification正常工作。我希望didActivateNotification允许我聚焦窗口并从通知中心删除通知。

下面是我的代码:notice.m

代码语言:javascript
复制
#import "Notice.h"

@implementation Notice

- (void) notify:(NSDictionary *)message {

    NSLog(@"Notification - Show it");

    NSUserNotification *notification = [[NSUserNotification alloc] init];
    [notification setTitle:[message valueForKey:@"title"]];
    [notification setInformativeText:[message valueForKey:@"content"]];
    [notification setDeliveryDate:[NSDate dateWithTimeInterval:0 sinceDate:[NSDate date]]];
    [notification setSoundName:NSUserNotificationDefaultSoundName];
    NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
    [center scheduleNotification:notification];
}

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{

    NSLog(@"Notification - Clicked");

    notification=nil;
    [center removeDeliveredNotification: notification];
}

这是正确的触发:

代码语言:javascript
复制
NSLog(@"Notification - Show it");

但这不是:

代码语言:javascript
复制
NSLog(@"Notification - Clicked");

有什么建议吗?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-03 08:21:34

您可能需要为NSUserNotificationCenter设置委托

代码语言:javascript
复制
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
center.delegate = self;

您还应该确保您的Notice类实现NSUserNotificationCenterDelegate协议。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13204746

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档