我有一组 c++/obj c 文件来为 Growl(即 Obj C)创建一种 C++ 包装器,但是我被困在一个部分。我需要在我的 Obj C 类中设置一个 Growl Delegate 以便调用注册。
这是我的.mm
#import "growlwrapper.h"
@implementation GrowlWrapper
- (NSDictionary *) registrationDictionaryForGrowl {
return [NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObject:@"Upload"], GROWL_NOTIFICATIONS_ALL,
[NSArray arrayWithObject:@"Upload"], GROWL_NOTIFICATIONS_DEFAULT
, nil];
}
@end
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: YES
clickContext: nil
];
[pool drain];
}
int main() {
showGrowlMessage("Hello World!", "This is a test of the growl system");
return 0;
}
和我的.h
#ifndef growlwrapper_h
#define growlwrapper_h
#include <string>
#include <iostream>
#include <Cocoa/Cocoa.h>
#include <Growl/Growl.h>
using namespace std;
void showGrowlMessage(std::string title, std::string desc);
int main();
#endif
@interface GrowlWrapper : NSObject <GrowlApplicationBridgeDelegate>
@end
现在你可以看到我[GrowlApplicationBridge setGrowlDelegate: @""];
被设置为一个空字符串,我需要将它设置为一些东西,以便registrationDictionaryForGrowl
被调用,目前没有被调用。
但我不知道该怎么做。有什么帮助吗?