2012-05-16 25 views
0

我正在嘗試構建一個使用Growl的基本可可應用程序。有沒有辦法使用GrowlApplicationBridge沒有NSClassFromString?

每次我想用GrowlApplicationBridge我有使用類似

Class GAB = NSClassFromString(@"GrowlApplicationBridge"); 
[GAB performSelector:@selector(setGrowlDelegate:) withObject:self]; 

我希望能夠只使用

[GrowlApplicationBridge setGrowlDelegate:self]; 

這裏的編譯器錯誤,我得到的,當我嘗試我想要的行爲:

Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_GrowlApplicationBridge", referenced from: objc-class-ref in StatusMenuAppDelegate.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

回答

2

只要您導入<Growl/Growl.h>在該文件的頂部並將框架鏈接到您的應用程序中,您應該可以使用[GrowlApplicationBridge setGrowlDelegate:self]就好了。

檢查文件的頂部並確保導入它,然後檢查目標的「鏈接庫和框架」構建階段並確保鏈接它。

+0

謝謝:)我在複製框架而不是鏈接它。 – Cyrus

+0

@Cyrus:你需要做這兩件事。如果你不復制它,你的應用程序將無法啓動,因爲你的用戶不會擁有它。如果你沒有鏈接它,複製它是沒有用的。您必須複製它(以便它會出現在用戶的機器上)並鏈接到它(以便您的應用程序將實際使用它)。 –

+0

明白了。謝謝你的幫助。 – Cyrus