是否将委托设置为我的类的实例? 我有一个C++的/Objc C文件集,为C++创建一个用于咆哮的C++包装(这是Objc),但是我被困在一个部分。我需要在Obj C类中设置一个咆哮委托,以便调用注册
这是我的是否将委托设置为我的类的实例? 我有一个C++的/Objc C文件集,为C++创建一个用于咆哮的C++包装(这是Objc),但是我被困在一个部分。我需要在Obj C类中设置一个咆哮委托,以便调用注册,c++,objective-c,growl,C++,Objective C,Growl,这是我的 #import "growlwrapper.h" @implementation GrowlWrapper - (NSDictionary *) registrationDictionaryForGrowl { return [NSDictionary dictionaryWithObjectsAndKeys: [NSArray arrayWithObject:@"Upload"], GROWL_NOTIFICATIONS_ALL,
#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;
}
#导入“growlrapper.h”
@实现growlrapper
-(NSDictionary*)注册词典FORGROWL{
返回[NSDictionary Dictionary WithObjectsAndKeys:
[NSArray arrayWithObject:@“上传”],咆哮着发出所有通知,
[NSArray arrayWithObject:@“Upload”],咆哮通知\u默认值
,无];
}
@结束
void showGrowlMessage(std::string title,std::string desc){
std::cout您需要创建growlrapper
的实例,并将其作为委托传递给setgrowlelegate:
方法。您只想在应用程序中执行一次此操作,因此每次调用showGrowlMessage
时设置它并不理想。您还需要保留对该growlrapper的强引用ode>这样,您可以在使用完它后释放它,或者如果您使用ARC,它将保持有效。因此,从概念上讲,您在启动时需要以下内容:
growlWrapper = [[GrowlWrapper alloc] init];
[GrowlApplicationBridge setGrowlDelegate:growlWrapper];
关闭时:
[GrowlApplicationBridge setGrowlDelegate:nil];
[growlWrapper release]; // If not using ARC
我收到一个错误growlrapper.mm:15:error:“growlrapper”未在此范围内声明(这一行是growlrapper alloc行,我需要将growlrapper添加到我的.h文件中吗?抱歉,我有点糊涂:(是的,您需要在某个地方声明GrowlRapper。如果您只想让测试正常运行,最简单的方法就是在alloc/init之前插入GrowlRapper*GrowlRapper;
)。
[GrowlApplicationBridge setGrowlDelegate:nil];
[growlWrapper release]; // If not using ARC