2013-05-09 91 views
0

我想以編程方式在iOS中的單個郵件中發送多個附件文件。我已嘗試以下內容:如何在iOS中的單個郵件中附加多個文件

// 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]; 

通過使用此代碼,我只能發送一個附件。然而,我想發送多個文件。我怎樣才能做到這一點?

+0

調用方法'-addAttachmentData:mime類型:文件名:'任何時間你想添加一個附件,它是一種_add_不是一種方法(見前綴)......差異是顯而易見的,但如果你不確定,文檔也可以幫助你。 – holex 2013-05-09 11:55:04

+0

下面是另一個堆棧流量鏈接http://stackoverflow.com/questions/5107926/how-do-i-attach-multiple-images-to-an-email-on-the-iphone這可能會幫助你 – Impossible 2013-05-09 11:27:34

回答

1

你增添不少時間addAttachmentData並添加muliple文件

試試這個代碼: - 加入這一行

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]; 
0
if([MFMailComposeViewController canSendMail]) 
     { 
      [mailController setMailComposeDelegate:self]; 
      NSString* [email protected]""; 
      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]; 
     } 
相關問題