0

我在电子邮件作曲家中有一些像AppDelegate.imageArray 这样的数组图像我想将此数组发送给我的示例代码

if ([MFMailComposeViewController canSendMail]) {
        MFMailComposeViewController *composeViewController = [[MFMailComposeViewController alloc] initWithNibName:nil bundle:nil];
        [composeViewController setMailComposeDelegate:self];
        [composeViewController setToRecipients:@[@"example@email.com"]];
        [composeViewController setSubject:@"example subject"];
        [composeViewController setMessageBody:appDelegate.imageArray isHTML:NO];
[self presentViewController:composeViewController animated:YES completion:nil];

但我收到错误,例如无法使用类型的右值初始化 NSString 类型的参数NSMuttableArray

4

3 回答 3

4
if ([MFMailComposeViewController canSendMail]) {
        MFMailComposeViewController *composeViewController = [[MFMailComposeViewController alloc] initWithNibName:nil bundle:nil];
        [composeViewController setMailComposeDelegate:self];
        [composeViewController setToRecipients:@[@"example@email.com"]];
        [composeViewController setSubject:@"example subject"];
        [composeViewController setMessageBody:@"Images" isHTML:NO];
        for (int i = 0; i < [appDelegate.imageArray count]; i++)
        {
             UIImage *Image = [appDelegate.imageArray objectAtIndex:i];
             NSData *myData = UIImagePNGRepresentation(Image);
             [composeViewController addAttachmentData:myData mimeType:@"image/png"                  fileName:@"Image.png"];
        }

[self presentViewController:composeViewController animated:YES completion:nil];
于 2013-08-05T13:11:47.870 回答
0

MessageBody 是简单的字符串,如果要附加图像,可以使用如下内容:

[composeViewController addAttachmentData:imageData mimeType:@"image/jpeg" fileName:fileName];

您附加的文件会因类型而异。

于 2013-08-05T13:09:57.050 回答
0

在这里只需用你的 Arr 调用这个函数

-(NSMutableString)createImgMailBodyFromArray:(NSMutableArray *)arr{

    //Create a string with HTML formatting for the email body
    NSMutableString *emailBody = [[NSMutableString alloc] initWithString:@"<html><body>"];


    for (int i = 0; i<[arr count]; i++) {
        UIImage *emailImage = [arr objectAtIndex:i];
        //Convert the image into data
        NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
        //Create a base64 string representation of the data using NSData+Base64
        NSString *base64String = [imageData base64EncodedString];
        //Add the encoded string to the emailBody string
        //Don't forget the "<b>" tags are required, the "<p>" tags are optional
        [emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'></b></p>",base64String]];
    }


    return emailBody;

}

现在就这样称呼

if ([MFMailComposeViewController canSendMail]) {
        MFMailComposeViewController *composeViewController = [[MFMailComposeViewController alloc] initWithNibName:nil bundle:nil];
        [composeViewController setMailComposeDelegate:self];
        [composeViewController setToRecipients:@[@"example@email.com"]];
        [composeViewController setSubject:@"example subject"];
        [composeViewController setMessageBody:[self createImgMailBodyFromArray:YOUR_ARR] isHTML:NO];
[self presentViewController:composeViewController animated:YES completion:nil];
    }

而“NSData+base64”文件在这里你可以找到https://github.com/l4u/NSData-Base64

于 2013-08-05T13:17:09.963 回答