OS X で特権ヘルパー ツールとして実行する必要があるサーバーを作成しNSSocketPort
てNSFileHandle
いNSNotificationCenter
ます。ただし、NSNotificationCenter
通知ハンドラの呼び出しを拒否します。関連するコードは次のとおりです。
NSSocketPort* sock = [[NSSocketPort alloc] initWithTCPPort:8080];
NSFileHandle* listener = [[NSFileHandle alloc] initWithFileDescriptor:sock.socket closeOnDealloc:NO]
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(onConnection:) name:NSFileHandleConnectionAcceptedNotification object:nil]
私のメインスレッドは実行[NSRunLoop.mainRunLoop run]
中なので、それは問題ではありません。addObserver:
呼び出しで「オブジェクト」を「リスナー」に設定しようとしましたが、違いはありませんでした。