0

複数の添付ファイルを iOS でプログラム的に 1 つのメールで送信したい。これまでに次のことを試しました。

 // I give the file from array 
NSString *str_mail = [readingEmfReading objectAtIndex:0];
//  here I can encode the file
NSData *myData = [str_mail dataUsingEncoding:NSUTF8StringEncoding]
//here I can attach the file with extance of .csv
[controller addAttachmentData:myData mimeType:@".cvs" fileName:retriveEmail]  
//here I can set the body for mail 
[controller setMessageBody:@"file" isHTML:NO];
//here code for sent mail
if (controller) [self presentViewController:controller animated:YES completion:nil];

このコードを使用すると、添付ファイルを 1 つだけ送信できます。ただし、複数のファイルを送信したい。どうすればこれを達成できますか?

4

2 に答える 2

1

何度もaddAttachmentDataを追加し、複数のファイルを追加します

このコードを試してください:-この行を追加してください

NSString *str_mail = [readingEmfReading objectAtIndex:0];
//  here i can encoded the file
NSData *myData = [str_mail dataUsingEncoding:NSUTF8StringEncoding]

NSData *myData1 = [str_mail dataUsingEncoding:NSUTF8StringEncoding]
//here i can attach the file with extance of .csv
[controller addAttachmentData:myData mimeType:@".cvs" fileName:retriveEmail]  
//here i can set the body for mail 


// For second file 

NSData *myData1 = [str_mail dataUsingEncoding:NSUTF8StringEncoding]

[controller addAttachmentData:myData1 mimeType:@".cvs" fileName:retriveEmail] 

[controller setMessageBody:@"file" isHTML:NO];
//here code for sent mail
if (controller) [self presentViewController:controller animated:YES completion:nil];
于 2013-05-09T11:32:01.007 に答える
0
if([MFMailComposeViewController canSendMail])
        {
            [mailController setMailComposeDelegate:self];
            NSString* message=@"";
            NSString *filePath;
            for (int i=0; i<filesarray.count; i++)
            {
                if (i==filesarray.count-1)
                {
                    message=[message stringByAppendingFormat:@"%@ ",[filesarray objectAtIndex:i]];
                }
                else if (i==filesarray.count-2)
                {
                    message=[message stringByAppendingFormat:@"%@ and ",[filesarray objectAtIndex:i]];
                }
                else
                    message=[message stringByAppendingFormat:@"%@, ",[filesarray objectAtIndex:i]];
                NSString *datPath =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
                datPath = [datPath stringByAppendingFormat:@"/%@.csv",[filesarray objectAtIndex:i]];
                filePath = datPath;
                [mailController addAttachmentData:[NSData dataWithContentsOfFile:filePath] mimeType:@"text/csv" fileName:[NSString stringWithFormat:@"%@.csv",[filesarray objectAtIndex:i]]];
            }
            [mailController setSubject:message];
            [mailController setMessageBody:@"" isHTML:NO];
            [self presentModalViewController:mailController animated:YES];
        }
于 2013-05-09T11:42:16.710 に答える