我想做的是在我的 ipod touch 上启用一个简单的 bonjour 服务。在我发布我的自定义 bonjour 服务后,委托人没有收到“netServiceDidPublish:”调用。我还检查了“netService:(NSNetService *)sender didNotPublish:”中没有任何错误消息。以下是我的代码部分:
// AsyncSocket class comes from an awesome project: cocoa async socket.
// http://code.google.com/p/cocoaasyncsocket/
AsyncSocket* listenSocket;
listenSocket = [[AsyncSocket alloc] initWithDelegate:self];
NSError *error;
if (![listenSocket acceptOnPort:0 error:&error])
{
NSLog(@"Error starting server: %@", error);
return NO;
}
int port = [listenSocket localPort];
NSLog(@"Server started on port: %hu", port);
isRunning = YES;
// register itself to bonjour service.
netService = [[[NSNetService alloc] initWithDomain:@"local."
type:@"_sampleservice._tcp"
name:@"myservice"
port:port] autorelease];
if (!netService)
{
NSLog(@"Failed to enable net service");
[listenSocket disconnect];
return NO;
}
[netService setDelegate:self];
[netService scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
//[netService publishWithOptions:NSNetServiceNoAutoRename];
[netService publish];
在此代码部分之后,我可以获得“netServiceWillPublish”委托调用,但没有“netServiceDidPublish”有人知道吗?提前致谢。