我试图从另一个类(而不是在“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];
}但是asyncSocket在netClass中的方法,如"didAcceptNewSocket“、"socketDidDisconnect”、"netServiceDidPublish",并没有被称为。
知道怎么称呼它吗?
如有任何帮助,将不胜感激:)
发布于 2012-05-21 15:48:59
您需要通过向任何您的setDelegate:对象发送NSNetService消息来设置委托--从您发布的代码看,它是"netService“([netService setDelegate:self];)。
将"NSApplicationDelegate, NSNetServiceDelegate, GCDAsyncSocketDelegate“放入.h文件并不会设置委托,它基本上只是让编译器知道您打算实现这些协议的方法。而且,您不应该在那里有NSApplicationDelegate,因为您已经有了一个应用程序委托。
https://stackoverflow.com/questions/10676780
复制相似问题