1

I call a method from background thread as follows.

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    UIApplication *app = [UIApplication sharedApplication];

    //create new uiBackgroundTask
    __block UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];

    //and create new timer with async call: 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //run function methodRunAfterBackground
        NSTimer* t = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(methodRunAfterBackground) userInfo:nil repeats:YES];
        [[NSRunLoop currentRunLoop] addTimer:t forMode:NSDefaultRunLoopMode];
        [[NSRunLoop currentRunLoop] run];
    });
}

After 15 seconds, I have to make a call to a number. I use [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_number]]];but unable to make a call while application is in background state. Can we make a call from background state? If yes, how?

Deepak Thakur
  • 3,453
  • 2
  • 37
  • 65
  • 1
    You can't make a call to `openURL` from the background as that will change the current foreground app and that isn't allowed for usability reasons. – Paulw11 Dec 12 '16 at 11:15
  • You need to call `openURL` from the main thread, however as @Paulw11 mentioned even if you do that you still might not be able to call. – Cristik Dec 12 '16 at 17:55

0 Answers0