MFMailComposeViewController 根据收件人对发送的电子邮件做出反应

MFMailComposeViewController reacting to sent emails based on recipient

我有一个按钮,允许用户向支持地址发送电子邮件。还可以选择使用电子邮件与其他用户共享内容。

在后一种情况下,将跟踪用户通过电子邮件共享的事实以进行统计分析。

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

if (result == MFMailComposeResultSent){
    [[TrackingHelper sharedTracker] trackEvent:@"Product" action:@"SharedViaEmail" label:self.product.name];

}

[self dismissViewControllerAnimated:YES completion:NULL];

}

由于这会在用户通过电子邮件分享和用户发送支持电子邮件时调用,我想知道是否有办法在委托中区分这两者? MFMailComposeResult 没有用,因为它只 returns 无论它是否成功。我希望通过检索已发送邮件的收件人并将其与支持地址进行匹配来确定,但据我所知没有办法做到这一点。

有谁知道有没有办法做到这一点?

我通常这样做的方式是定义一个变量来跟踪激活了哪个选项。

选择"support email"时,设置标志isSupportEmail = YES 否则 NO.

然后,在 mailComposeController 中,

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{
    if (result == MFMailComposeResultSent)
    {
        if(isSupportEmail)
            [[TrackingHelper sharedTracker] trackEvent:@"Support" action:@"SupportViaEmail" label:self.product.name];
        else
            [[TrackingHelper sharedTracker] trackEvent:@"Product" action:@"SharedViaEmail" label:self.product.name];
    }

    [self dismissViewControllerAnimated:YES completion:NULL];
}