0

嘿那里,所以我有一个 NSObject 子类通过通知中心发送消息,我将通知发送到对象 nil 但唯一可以接收通知的对象是发送它们的对象

我同时发送了两个通知(以测试它是否是线程问题)

[[NSNotificationCenter defaultCenter] postNotificationName:kWGAskingForAuthToken object:nil];

int status = 123;
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"RAR" forKey:@"Status"];
NSNotification *note = [NSNotification notificationWithName:kWGAskingForAuthToken  object:nil userInfo:userInfo];
[[NSNotificationCenter defaultCenter] performSelectorOnMainThread:@selector(postNotification:) withObject:note waitUntilDone:YES];

我的观察者也一样简单

[[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(handleMyEvent:)name:kWGAskingForAuthToken object:nil]; 

它是一个单独的对象中的同一个观察者,它没有收到通知

4

2 回答 2

0

很遗憾,但我从未设法找到答案,相反,我只是开始向对象发送消息,而不是在全局范围内使用它们。

于 2010-07-30T09:25:54.937 回答
0

这对我来说似乎是正确的方法。唯一的问题是“kWGAskingForAuthToken 在哪里定义?” 是否有可能在多个地方定义?可能不一样?

于 2010-07-14T22:46:40.963 回答