我需要從我的可可應用程序向我的firebreath項目發送一個分佈式通知,所以我需要在我的firebreath代碼中創建一個觀察者和一個選擇器。 爲了支持Objective-C代碼,我將類擴展名更改爲「.mm」。我的firebreath項目中已經有Objective-C代碼,並且工作正常。但是當我嘗試創建觀察者時,我的代碼中出現錯誤,我不知道如何解決它。需要在我的Firebreath項目中添加一個NSDistributedNotification觀察者
這裏是firebreath項目我的源代碼:
//This is the selector
- (void)receiveAppConfirmationNotification:(NSNotification*)notif{
//The application is alive.
NSLog(@"The application is alive!!!!!!!!");
}
std::string MyProjectAPI::bgp(const std::string& val)
{
//Add an observer to see if the application is alive.
NSString *observedObject = @"com.test.net";
NSDistributedNotificationCenter *center = [NSDistributedNotificationCenter defaultCenter];
[center addObserver: self
selector: @selector(receiveAppConfirmationNotification:)
name: @"App Confirmation Notification"
object: observedObject];
}
這裏是我的錯誤:
... firebreath /../項目/ MyProject的/ MyProjectAPI.mm:133:錯誤:預期' - '標記之前的非限定標識。這是我定義「receiveAppConfirmationNotification」方法的路線。
... firebreath /../ projects/MyProject/MyProjectAPI.mm:157:錯誤:'self'未在此範圍內聲明。
如何定義選擇器? 我該如何添加觀察者作爲類本身?
有使用客觀C對象的幾個例子在firebreath codebase中使用firebreath。 – taxilian 2011-12-30 21:13:01