开发者

Unexplained crash AFTER sending an email using MFMailComposer

In my app, I have email sending code.

It's qu开发者_StackOverflowite plain-vanilla (pasted at end of question).

What happens is the following sequence: - Click the "EMAIL" button of my app, that calls the sendEmail method - Click the To field - Type an email address - Click the MFMailComposer Send button - The email is sent (and arrives - I typically set my own email address) - The application crashes... with this stack crawl:

2011-07-25 11:21:21.179 MyApp[2769:3d0b] -[__NSCFString searchQuery:returnedResults:]: unrecognized selector sent to instance 0x3c3410
2011-07-25 11:21:21.201 MyApp[2769:3d0b] uncaughtExceptionHandler
2011-07-25 11:21:21.202 MyApp[2769:3d0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString searchQuery:returnedResults:]: unrecognized selector sent to instance 0x3c3410'

What I notice is the following: 1. As I type the the To address, the debugger output shows CPSqliteStatementSendResults: interrupted 2. If I add a setToRecipients (effectively "hard-coding" the To email address), the application doesn't crash...

Any ideas? (code below)

- (void)sendEmail:(id)sender {
    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;

    [controller setSubject:@"The Subject"];

    [self presentModalViewController:controller animated:YES];
    [controller release];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller  
          didFinishWithResult:(MFMailComposeResult)result 
                        error:(NSError*)error;
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            break;
        case MFMailComposeResultSaved:
            break;
        case MFMailComposeResultSent:
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Sending Failed");
            break;
        default:
            NSLog(@"Message not sent");
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}


Try not to release the MFMailComposeViewController immediately but in his delegate method didFinishWithResult (at the very end).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜