0

Growl(Obj C)の一種のC++ラッパーを作成するためのc++ / obj cファイルのセットがありますが、一部に固執しています。登録が呼び出されるように、GrowlDelegateをObjCクラス内の何かに設定する必要があります。

これは私の.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: @""];のとおり、空の文字列に設定されているので、registrationDictionaryForGrowlgetsが呼び出されるように設定する必要がありますが、現在は呼び出されていません。

しかし、私はそれを行う方法を理解することはできません。何か助けはありますか?

4

1 に答える 1

0

のインスタンスを作成し、これをメソッドGrowlWrapperのデリゲートとして渡す必要があります。setGrowlDelegate:これはアプリケーションで1回だけ実行する必要があるため、呼び出すたびに設定するのshowGrowlMessageは理想的ではありません。また、これを強く参照して、使いGrowlWrapper終わったときにリリースできるようにするか、ARCを使用している場合に有効なままにしておくこともできます。したがって、概念的には、起動時に次のようなものが必要になります。

growlWrapper = [[GrowlWrapper alloc] init];
[GrowlApplicationBridge setGrowlDelegate:growlWrapper];

そしてシャットダウン時:

[GrowlApplicationBridge setGrowlDelegate:nil];
[growlWrapper release];    // If not using ARC
于 2012-07-21T16:53:29.740 に答える