2
10.7.2我無法獲得標準NSDistributedNotifications以開箱即用。NSDistributedNotifications未在(相同)應用程序的實例之間分佈
即使(在https://github.com/dirkx/Example-NSDistribtuedNotification-Failing完整的XCode版)帶回只是下面我簡單的東西得到:
- 漂漂工作的通知「本地」(就像用NSNotificationCenter),但
- 沒有間-app通信當我啓動應用程序兩次(例如,從命令行)
- 當另一個應用程序註冊此(或n)時沒有通知
- Distnote守護進程日誌中沒有調試/信息。
我錯過了什麼?
NSString * kSayNotification = @"org.webweaving.sayExample";
// Send a Distributed Notification on button press.
//
-(IBAction)buttonChange:(NSButton *)sender {
NSString * str = (sender.state == NSOnState) ? @"Yes" : @"No";
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:kSayNotification
object:str
];
}
// Update a label on receiving a Notification.
//
-(void)notif:(NSNotification *)nf {
.. snipped time string ...
// Textfield with the time of arrival and the value passed in the notification.
//
textField.stringValue = [NSString stringWithFormat:@"%@: %@",
dStr, (NSString *)nf.object
];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Register for the notifications.
//
[[NSDistributedNotificationCenter defaultCenter]
addObserver:self
selector:@selector(notif:)
name:kSayNotification
object:nil];
}
作爲題外話 - 通知觀察者(https://github.com/melo/notification-watcher)不顯示Notifiactions - 但通知是在應用內處理。
註冊通知的代碼是什麼樣的? – sbooth 2012-02-04 12:37:20
這是 - (void)applicationDidFinishLaunching中的函數:(NSNotification *)在上面的aNotification(或查看實際git的鏈接https://github.com/dirkx/Example-NSDistribtuedNotification-Failing/blob/master/SayHi /SayHi/AppDelegate.m - 第56行及以後)。 – 2012-02-04 13:32:40
謝謝,我想我早些時候忽略了這一點。 – sbooth 2012-02-04 14:30:48