咆哮通知 - 不会使用框架(Mist)触发通知
我正在为 Growl 1.3.1 SDK 开发一个小型包装器。更具体地说,我想将 Growl 打包在我的应用程序中,这样即使用户没有 Growl,他们仍然能够收到通知。我之前安装了 Growl,我的代码会发出通知。我已经卸载了 Growl,只使用框架;雾,我相信它被称为。但是,当我现在启动代码(Growl 已卸载)时,不会触发任何通知!下面是我当前正在使用的代码:
#import "growlwrapper.h"
void showGrowlMessage(std::string title, std::string desc) {
std::cout << "[Growl] showGrowlMessage() called." << std::endl;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[GrowlApplicationBridge setGrowlDelegate: @""];
[GrowlApplicationBridge
notifyWithTitle: [NSString stringWithUTF8String:title.c_str()]
description: [NSString stringWithUTF8String:desc.c_str()]
notificationName: @"Upload"
iconData: nil
priority: 0
isSticky: NO
clickContext: nil
];
[pool drain];
}
int main() {
showGrowlMessage("Hello World!", "This is a test of the growl system");
return 0;
}
我也有适当的 Growl Registration 字典,并且正在编译:
g++ growlwrapper.mm -framework Growl -framework Foundation -o growltest
这段代码有什么问题吗?有什么想法为什么它不会被解雇吗?
编辑:上面的代码似乎工作得很好。只需要处于运行循环中,并使用适当的 Growl 字典内容即可。
I'm working on a small wrapper for the Growl 1.3.1 SDK. More specifically, I'd like to package Growl in my application so that even if the user doesn't have Growl, they will still be able to get notifications. I previously had Growl installed and my code would fire a notification. I have since uninstalled Growl and am using just the framework; Mist, I believe it is called. However, when I launch the code now (that Growl is uninstalled), no notification is fired! Below is the code I am currently working with:
#import "growlwrapper.h"
void showGrowlMessage(std::string title, std::string desc) {
std::cout << "[Growl] showGrowlMessage() called." << std::endl;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[GrowlApplicationBridge setGrowlDelegate: @""];
[GrowlApplicationBridge
notifyWithTitle: [NSString stringWithUTF8String:title.c_str()]
description: [NSString stringWithUTF8String:desc.c_str()]
notificationName: @"Upload"
iconData: nil
priority: 0
isSticky: NO
clickContext: nil
];
[pool drain];
}
int main() {
showGrowlMessage("Hello World!", "This is a test of the growl system");
return 0;
}
I also have the appropriate Growl Registration dictionary, and am compiling with:
g++ growlwrapper.mm -framework Growl -framework Foundation -o growltest
Is there anything wrong with this code? Any ideas why it wouldn't be firing?
Edit: Seems the code above is working just fine. Just needed to be in a run loop, with the appropriate Growl dictionary stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 Growl 方面的权威,但我有一个很好的预感:当安装 Growl 应用程序时,像这样的一次性通知会起作用,因为正在运行的应用程序有一个运行循环,并且可以从它。在您这里的示例中,没有运行循环,因此这个一次性应用程序无法绘制任何通知 - 它甚至在有机会之前就死了。我猜想如果您制作了一个样板 Cocoa 应用程序,然后从
applicationDidFinishLaunching:
调用showGrowlMessage
,但在您终止/退出该应用程序之前,我打赌它会起作用。至少你应该尝试一下。编辑:如果您创建一个新的Cocoa非文档应用程序,并将以下方法添加到appDelegate类中,它将成功使用Mist(即应用程序内)Growl显示通知。
因此,简而言之,原始代码的问题不仅仅是 runLoop 问题,而是它没有将真正的委托(即根据需要实现标头中描述的委托方法的对象)传递给 GrowlApplicationBridge(它传递了一个空的委托)细绳)。您肯定仍然需要一个 runLoop,但这还不是全部——使用这个框架还有额外的、非可选的设置。
I'm not an authority on Growl, but I have a pretty good hunch: When the Growl app is installed, a one-shot notification like this has a prayer to work, because the running app has a run loop and can drive UI from it. In the example you have here, there's no run loop, so there's no way for this one-shot app to ever draw any notifications -- it's dead before it even has a chance. I would guess if you made a boilerplate Cocoa app, and then called
showGrowlMessage
fromapplicationDidFinishLaunching:
, but before you terminated/quit the app, I bet it would work. At the very least you should give that a try.EDIT: If you create a new Cocoa non-document application, and add the following methods to the appDelegate class, it will successfully display a notification using the Mist (i.e. in-app) Growl.
So, in short, the problem with the original code was not only the runLoop problem, but that it was not passing a real delegate (i.e. object that implements the delegate methods described in the headers as required) to the GrowlApplicationBridge (it passes an empty string). You definitely still need a runLoop, but that's not all -- there's additional, non-optional setup for using this framework.