2

我只是想向 Gyazo 应用程序添加一些通知。我终于能够向通知中心发送通知http://korniltsev.ru/p/jz6m3Nm.png 但是当我点击它并且应用程序没有启动时,它以某种奇怪的方式启动:它显示空窗口(即使我将它 visibleAtLaunch 设置为 0) 并且没有任何反应;http://korniltsev.ru/p/jz6mvk0.png

我尝试使用的代码在这里:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

    NSUserNotification * clicked = [[aNotification userInfo]
            objectForKey:NSApplicationLaunchUserNotificationKey];
    if (clicked){
        [NSApp terminate:self];
        return;
    }
...

我发送这样的通知

NSUserNotificationCenter *manager = [NSUserNotificationCenter defaultUserNotificationCenter];
NSUserNotification *urlNotification = [[NSUserNotification alloc]init];
[urlNotification setTitle:appName];
[urlNotification setInformativeText:url];
[manager deliverNotification:urlNotification];

我究竟做错了什么?

4

1 回答 1

1

[NSApp terminate:self]有很多副作用。您确定这些副作用不会创建您的空白窗口吗?您是否尝试过[NSApp terminate:self]立即调用applicationDidFinishLaunching并确保您的应用程序在每种情况下都干净地退出?如果没有,您可能需要查看您在应用程序的文档控制器(如果有的话)和applicationShouldTerminate.

于 2012-07-29T21:56:16.807 回答