AppDelegate
and
PackagetTunnelProvider
use
NSTimer
in the same way:
The
-[NSTimer scheduledTimerXxx
] API creates an
NSTimer
that’s schedule in the run loop associated with the current thread. When you call it from app code, you’re typically running on the main thread, and the main thread is guaranteed to run its run loop, and hence call your timer. None of the threads within a packet tunnel provider are guaranteed to run their run loop. If you
must use
NSTimer
, or any other run-loop based construct, you’ll need to create a thread specifically dedicated to running the run loop and schedule your run loop sources on that.
However, in most cases it’s possible to avoid run loop based constructs in a packet tunnel provider, and that’s what I recommend you do. For example, you can implement a timeout using a Dispatch timer source rather than
NSTimer
.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"