我正在尝试从另一个类启动套接字(不在"applicationDidFinishLaunching"中(,因此,在AppDelegate.m中,我调用了类netClass:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
netClass *network = [[netClass alloc] init];
[network startNet];
}
而在netClass中,方法startNet正常启动套接字:
- (void)startNet
{
[DDLog addLogger:[DDTTYLogger sharedInstance]];
...
[netService publish];
}
但是 netClass 中的 asyncSocket 方法,如 "didAcceptNewSocket"、"socketDidDisconnect"、"netServiceDidPublish",没有被调用。
知道怎么称呼它吗?
任何帮助将不胜感激:-(
通过向NSNetService对象发送setDelegate:
消息来设置委托 - 从您发布的代码来看,这是"netService
"([netService setDelegate:self];
(。
将"NSApplicationDelegate, NSNetServiceDelegate, GCDAsyncSocketDelegate
"放在.h文件中不会设置委托,它基本上只是让编译器知道您打算实现这些协议的方法。此外,您不应该在那里NSApplicationDelegate
,因为您已经有一个应用程序委托。