0
我有一個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
被調用,目前沒有被調用。
但我不知道該怎麼做。任何幫助?
我得到一個錯誤'growlwrapper.mm:15:錯誤:「growlWrapper」在未聲明這個範圍(這一行是GrowlWrapper的分配線,我需要將growlWrapper添加到我的.h文件中嗎?對不起,我是一個noob :( – Steven 2012-07-21 17:02:10
是的,你需要在某處聲明growlWrapper。最簡單的東西如果你只是想讓你的測試工作就是在你分配/初始化之前插入'GrowlWrapper * growlWrapper'。 – 2012-07-21 17:10:29