私を助けてくれている人に事前に感謝します。
私は単純なデーモンを持っています。クラスを割り当ててから、スケジュールされた繰り返しのNSTimerを開始します。
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(usage3GviaSysctl) userInfo:nil repeats:YES];
次に、CFRunLoopRun()を呼び出して、デーモンが存続するようにします。
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
signal(SIGTERM, (sig_t)SIGTERM_handler);
helper = [[NMDaemonHelper alloc] init];
[helper startNotificationServer];
CFRunLoopRun();
NSLog(@"NMDAEMON: will exit");
[pool release];
return 0;
}
ここで問題となるのは、タイマーが起動した後、セグメンテーション違反が発生することです。bt:
objc_msgSend
__NSFireTimer
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
__CFRunLoopDoTImer
__CFRunLoopRun
CFRunLoopRunSpecific
タイマーを開始する他の方法も機能しませんでした。例えば:
NSTimer *timeUpdateTimer = [[NSTimer alloc] initWithFireDate:[NSDate date] interval:1 target:self selector:@selector(usage3GviaSysctl) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timeUpdateTimer forMode:NSDefaultRunLoopMode];
誰かが(wr)on(g)で何が起こっているのか考えていますか?