相关疑难解决方法(0)

Mac Mountain Lion从CLI应用程序发送通知

如何从命令行应用程序向通知中心发送通知?到目前为止我的尝试编译和运行,但没有成功通知我.

#import <Cocoa/Cocoa.h>

int main(int argc, const char * argv[]) {
    NSLog(@"Running notifications");

    NSUserNotification *note = [[NSUserNotification alloc] init];
    [note setTitle:@"Test"];
    [note setInformativeText:@"Woot"];

    NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
    [center scheduleNotification: note];

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我然后编译如下:

clang -framework cocoa /tmp/Notes.m
Run Code Online (Sandbox Code Playgroud)

我明白了

 2012-07-29 16:08:35.642 a.out[2430:707] Running notifications
Run Code Online (Sandbox Code Playgroud)

作为输出,但没有通知:(

这是一个因素吗?

cocoa objective-c nsnotificationcenter osx-mountain-lion nsusernotification

13
推荐指数
1
解决办法
3517
查看次数

将 OS X 10.8 通知中心 (NSUserNotification) 与 Java 结合使用

我在 OS X 10.8 中的通知中心遇到了困难。我编写了一个包装器来通过 JNA 提供对 NSUserNotification 和 NSUserNotificationCenter 类的 Java 访问,但功能有限。我能够发送通知,只要 .jar 通过 JavaApplicationStub 从 .app 包运行,它就会显示。但是,当通知样式设置为“警报”时,以下行始终会记录到控制台:

11/29/12 8:37:12.537 PM usernoted[162]: Failed to validate application at (null) -67061
Run Code Online (Sandbox Code Playgroud)

接下来,单击通知会导致以下内容记录到控制台:

11/29/12 8:38:15.291 PM usernoted[162]: Cannot find originating application to launch for event action.  file://localhost/Users/geoffodonnell/Projects/bin/GuiTest.app/ is not the same app as the one that sent the original notification.
Run Code Online (Sandbox Code Playgroud)

我确实为 NSUserNotificationCenter 类提供了委托,但是这些方法只有在 .jar 在包之外执行时才会运行。当然,这违背了目的,因为通知永远不会显示。

任何人都可以对上述两个错误提供任何见解吗?

我想知道 JavaApplicationStub 是否妨碍了我,但是当涉及到典型应用程序将如何响应通知中心事件时,我一无所知。

java macos jna nsusernotification

6
推荐指数
1
解决办法
2153
查看次数