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

ここで、この関数を 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 に答える
0

MessageBody は単純な文字列です。画像を添付する場合は、次のようなものを使用できます。

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

また、あなたが添付したファイルは、種類によって表現が異なります。

于 2013-08-05T13:09:57.050 に答える