Reputation: 2926
My app runs some tasks in the background, then in the end shows an alert asking the user if she wants to send the result by email.
In other places of the app I use the MFMailComposeViewController
in the same way as it should be (shown e.g. here). Here however, as I am in the completion block of a potentially long running task, I have no reference to a UIViewController
instance I could use for the following calls:
...
mailSendingController.mailComposeDelegate = self;
[self presentModalViewController:mailSendingController animated:YES];
I could probably keep the reference to the VC that invoked the task, but it might be dismissed before the task finishes.
What can I do? Create a fake hidden VC just to serve as the basis of the MFMailComposeViewController
? Is there a way to show MFMailComposeViewController
without an underlying VC? Use somehow the VC that is currently on top of the stack?...
Any ideas are welcome.
Upvotes: 2
Views: 297
Reputation: 4792
use ]
[UIApplication sharedApplication].keyWindow.rootViewController presentViewController: mailSendingController]
Upvotes: 1
Reputation: 5148
First of all, presentModalViewController:animated:
is deprecated as of iOS6 [1] you should use presentViewController:animated:completion:
[2]
I would just get the app's root view controller and then use that to present the modal view controller. That way it will be on top no matter what and you know the root view controller is always there.
Look at this question for some hints on accessing the app's root view controller.
Also, if you are going to do GUI stuff make sure you go back to the main thread:
dispatch_async(dispatch_get_main_queue(), ^{
// Present the VC here
});
Good luck!
Upvotes: 1