You can't use NSTimer unless you have a run loop.
So, instead use GCD which is better anyway:
static void dispatch_repeated_internal(dispatch_time_t firstPopTime, double intervalInSeconds, dispatch_queue_t queue, void(^work)(BOOL *stop))
{
__block BOOL shouldStop = NO;
dispatch_time_t nextPopTime = dispatch_time(firstPopTime, (int64_t)(intervalInSeconds * NSEC_PER_SEC));
dispatch_after(nextPopTime, queue, ^{
work(&shouldStop);
if(!shouldStop)
{
dispatch_repeated_internal(nextPopTime, intervalInSeconds, queue, work);
}
});
}
void dispatch_repeated(double intervalInSeconds, dispatch_queue_t queue, void(^work)(BOOL *stop))
{
dispatch_time_t firstPopTime = dispatch_time(DISPATCH_TIME_NOW, intervalInSeconds * NSEC_PER_SEC);
dispatch_repeated_internal(firstPopTime, intervalInSeconds, queue, work);
}
void test()
{
PJsipServices *sipServices = [PJsipServices sharePjsipServices];
dispatch_repeated(0.1, dispatch_get_main_queue(), ^(BOOL *stop) {
[sipServices readSignalLevel:nil];
// you might wanna set stop to YES to abort now
});
}
(Thanks to: https://stackoverflow.com/a/14582980/19851https://stackoverflow.com/a/14582980/19851)