I\'m trying to incorporate MFMailComposeViewController
in my app. When I present it modally, the send button works fine and the email is sent, which implies tha
Msoler has it right, teh action sheet is displayed off-screen. The MFMailComposeViewController display the action-sheet at x:y 0:0, so you have to make sure teh calling controller frame is at 0:0. I had a similar issue when I tried to display the MFMailComposeViewController from a view that was embedded in a scroll view.
I have implemented the same code . It works absolutely fine. When you click on the delete draft button,didFinishWithResult method is called and the mail is cancelled.
Method
(void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
is never called because you don't press any UIActionSheet
button after cancelling, as it doesn't show on screen.
The reason this is happening is that the UIActionSheet
appears off-screen. If you check the debug log you'll probably see a message saying Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:]
or -[UIActionSheet showFromToolbar:]
instead of -[UIActionSheet showInView:]
."
That's why you see your view getting darker, but no UIActionSheet
appears.
In my case, the problem was that my app is universal, but for some reason there was only one MainWindow.xib
, and it was larger than the iPhone screen size (it was, in fact, the iPad screen size).
The solution is to create another MainWindow-iPhone.xib
with the right dimensions and change the Info.plist entries called Main nib file base (iPad) and Main nib file base (iPhone) so that they point to the right file. Problem solved!
Hope it helps.
Just in case anybody else makes the same mistake as I did... I implemented the mailComposeController:didFinishWithResult:error:
method in my Swift code. It worked for a while but after several refactorings I noticed that it was suddenly not being called anymore. Eventually I noticed that the method had taken this form in my code:
private func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
}
So, as you can see I was a little bit too eager about privatizing my methods: Since the method is marked @optional
in the MFMailComposeViewControllerDelegate
you do not have to implement it. And while I actually had implemented it, the private
modifier from there on hid the implementation - thus, from outside the file it seemed that the method was actually not implemented, at all! However, since the method was optional, the compiler did not complain...
To conclude: Do not mark optional delegate with the modifier private
.
I have been wondering ever since learning Swift why there are no optional methods anymore - now I might have understood ;-).
I had the same problem,commented out '[picker release];'
, and it worked fine! Explanation? I have none.
Be sure that you use the correct method,
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
I had a some what similar method implemented which was never called. I have no idea what I exactly had but the compiler did not give me a warning or error message.