从联系人列表中选择电子邮件后,MFMailComposeViewController将无法打开

时间:2012-04-16 21:02:37

标签: objective-c ios email

我正在尝试向联系人列表中的联系人发送电子邮件。我使用的是ABPeoplePickerNavigationController。用户选择联系人的电子邮件后,会发生以下情况:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {

    if(property == kABPersonEmailProperty){
        [self dismissModalViewControllerAnimated:YES];
        ABMultiValueRef emails = ABRecordCopyValue(person, property);
        int index = ABMultiValueGetIndexForIdentifier(emails, identifier);
        NSString *emailValueSelected = (__bridge NSString*)ABMultiValueCopyValueAtIndex(emails, index);

        MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
        controller.mailComposeDelegate = self;
        [controller setSubject:@"the subject"];
        [controller setMessageBody:@"Hello there" isHTML:NO];
        [controller setToRecipients:[[NSArray alloc] initWithObjects:emailValueSelected, nil]];
        if (controller){
            [self presentModalViewController:controller animated:YES];
        }
        return NO;
    }
    return YES;
}

emailValueSelected变量具有正确的电子邮件值,并且所有代码似乎都没有任何问题(甚至是if(controller){...}语句的正文)。

问题是没有任何反应,电子邮件控制器永远不会显示。我已尝试使用[self presentViewController:controller animated:YES completion:nil][self presentModalViewController:controller animated:YES];

我在我的应用程序的另一部分使用完全相同的代码来发送电子邮件并且它正常工作,所以我猜它与人员选择器有关。

3 个答案:

答案 0 :(得分:0)

您使用的是标签栏控制器吗? 那你应该试试

[self.tabBarController presentModalViewController:controller animated:YES];

你也可以设置一个断点并做一个po控制器来看看控制器是否正确初始化(即它不是零)

答案 1 :(得分:0)

问题在于被解雇的人员选择器模式正在与试图出现的电子邮件模式发生冲突。我通过让人物选择器模态立即消失而不是动画来解决它。

if(property == kABPersonEmailProperty){
    [self dismissModalViewControllerAnimated:NO];
    //etc...
}

答案 2 :(得分:0)

我成功了:

[peoplePicker presentViewController:picker animated:YES completion:nil];

而不是:

[self presentViewController:picker animated:YES completion:nil];
相关问题