MFMailComposeViewController не исчезает из вида - PullRequest
3 голосов
/ 04 августа 2011

У меня есть следующий код, который вызывается при вызове кнопки на листе действий.Но когда я нажимаю «Отмена», а затем удаляю черновик, он просто замирает и не сбрасывает.Я использую тот же код в другом месте моего приложения, и он вызывается из выбранной ячейки таблицы, и он работает там.Есть идеи, почему он здесь не работает?

Также нет сообщения об ошибке в консоли при зависании.

if([MFMailComposeViewController canSendMail])
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"Dr. Chrono Support"];

    NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
    NSString* versionNum = [infoDict objectForKey:@"CFBundleVersion"];
    NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
    NSString *text = [NSString stringWithFormat:@"%@ %@",appName,versionNum];

    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@"contact@drchrono.com"]; 
    //NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
    //NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

    [picker setToRecipients:toRecipients];
    //[picker setCcRecipients:ccRecipients];  
    //[picker setBccRecipients:bccRecipients];

    // Attach an image to the email
    //NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
    //NSData *myData = [NSData dataWithContentsOfFile:path];
    //[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];

    // Fill out the email body text
    NSString *emailBody = text;
    [picker setMessageBody:emailBody isHTML:NO];

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

Ответы [ 2 ]

11 голосов
/ 04 августа 2011

Вам необходимо реализовать метод делегата:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {

Затем в этом методе делегата добавьте:

[self dismissModalViewControllerAnimated:YES];

, и он должен работать просто отлично.

Вам не нужно искать результат (только если вы хотите отобразить предупреждение «Спасибо» или что-то подобное, например, если пользователь действительно нажал «Отправить»)

0 голосов
/ 18 сентября 2013

Используйте следующий код

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{

    switch (result)
    {

        case MFMailComposeResultCancelled: 
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the Drafts folder");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send the next time the user connects to email");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was nog saved or queued, possibly due to an error");
            break;
        default:
            NSLog(@"Mail not sent");
            break;
    }

    [self dismissModalViewControllerAnimated:YES];
}
...