In my multi-tab app a thread cares about listening for messages coming from the server and it must be able to close a UIImagePickerController in case the camera is active while a specific message is received. The thread is run through NSThread detachNewThreadSelector.
I managed to invoke the right sequence of calls on the thread side through the ApplicationDelegate but the picker is not dismissed:
- (void) closeCameraController {
[cameraTabController closeSubViewCamera]; // Invokes cancel: on the cameraSubView.
}
The same sequence works properly when I start it through an event mapped on a button of the camera overlay (a ‘Cancel’ button):
- (IBAction) cancel {
[[self parentViewController] dismissModalViewControllerAnimated:NO];
}
From Apple’s Docs:
You can use NSObject’s performSelectorOnMainThread:withObject:waitUntilDone: