AppDelegate and PackagetTunnelProvider use NSTimer in the same way:
[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(expireTime) userInfo:nil repeats:NO];
The -expireTime in AppDelegate runs in 10 seconds, but not in PacketTunnelProvider.
What's the reason?
it works this way
Right, but I recommend you avoid this approach for two reasons:
It assumes that the main thread runs its run loop, which is not guaranteed by the NE provider API. An NE provider’s main thread could just as easily call
, which would cause the main queue to run but not the main thread’s run loop.dispatchMainIt gets you into the business of cross run loop scheduling and unscheduling. While this is supported, in my experience it’s problematic for two reasons:
I’ve seen cases while cross run loop schedule exposes obscure bugs in the OS.
Even if the OS side of this works perfectly, it’s easy to fall foul of race conditions in your own code.
I have another question:
Probably best to put that in a new thread but I’m still ‘litigating’ this issue (-:
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"