Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
邮件功能可以';无法在iOS中发送给收件人_Ios_Objective C_Mfmailcomposeviewcontroller - Fatal编程技术网

邮件功能可以';无法在iOS中发送给收件人

邮件功能可以';无法在iOS中发送给收件人,ios,objective-c,mfmailcomposeviewcontroller,Ios,Objective C,Mfmailcomposeviewcontroller,我用xcode创建了邮件发送函数 - (void)onShareBtn:(UIButton *)button { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setSubject:@"Hello!"]; // Set up the recipients.

我用xcode创建了邮件发送函数

- (void)onShareBtn:(UIButton *)button
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"Hello!"];

    // Set up the recipients.
    NSArray *toRecipients = [NSArray arrayWithObjects:@"first@gmail.com",
                             nil];
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@gmail.com",
                             nil];
    NSArray *bccRecipients = [NSArray arrayWithObjects:@"third@gmail.com",
                              nil];

    [picker setToRecipients:toRecipients];
    [picker setCcRecipients:ccRecipients];
    [picker setBccRecipients:bccRecipients];
    [picker setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

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

    // Fill out the email body text.
    NSString *emailBody = @"It is raining!";
    [picker setMessageBody:emailBody isHTML:NO];

    // Present the mail composition interface.
    [self presentModalViewController:picker animated:YES];
}

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    if(error)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error" message:[NSString stringWithFormat:@"error %@",[error description]] delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];
        [alert show];
        [self dismissViewControllerAnimated:YES completion:NULL];
    }
    else
    {
        switch (result)
        {
            case MFMailComposeResultCancelled:
                NSLog(@"Mail cancelled");
                break;
            case MFMailComposeResultSaved:
                NSLog(@"Mail saved");
                break;
            case MFMailComposeResultSent:
                NSLog(@"Mail sent");
                break;
            case MFMailComposeResultFailed:
                NSLog(@"Mail sent failure: %@", [error localizedDescription]);
                break;
            default:
                break;
        }

        // Close the Mail Interface
        [self dismissViewControllerAnimated:YES completion:NULL];
    }
}

此代码只能显示邮件表单,当我单击“发送”按钮时,它无法将邮件正确发送给收件人。 此函数仅显示发送邮件表单。
如何为正确发送给收件人的邮件更新此代码?

请注意,您无法从iOS模拟器发送邮件。“它无法正确发送邮件给收件人”这是什么意思。我尝试在ipad上运行。但现在我的问题如下。由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因是:“应用程序试图在目标上呈现无模式视图控制器”。***第一次抛出调用堆栈:(0x31f4b3e7 0x33d16963 0x3AACDE0D5 0x3AADFFB 0xbfc97 0x3AACDD03F 0x3AACDCF3 0x3AACDC883 0x3AACDCDD71 0x3AAC055C1 0x3AABF28A9 0x3AABF21B7 0x352b45f7 0x352b4227 0x31f203e7 0x31f2038b 0x31F10F 0x31e9223d 0x31e920c9 0x352b333b 0x3AAC46289 0xbc421 0xbc3a8)libc++abi.dylib:终止调用exception@Parser这意味着邮件发送表单显示结果发送过程已成功完成。但我没有收到任何邮件shamsudheen@triassicsolutions.com.may我知道我犯了什么错误。@ammoe。检查骰子的发件箱,无论它是否成功发送