我有10张图片被收集并导入到电子邮件中,用户将发送图像,但它们会一直显示为附件,我需要将图像作为一个接一个而不是附件。我在考虑一个pdf,但我不知道如何生成一个...
这是我的代码:
- (IBAction)openMail:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Contents Concepts Photo report"];
[mailer.view setNeedsDisplay];
NSString *path = [[NSBundle mainBundle] pathForResource:@"ContentsConceptsLogoFinal6copy" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[mailer addAttachmentData:myData mimeType:@"image/png" fileName:@"photo name"];
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"png"];
NSData *myData1 = [NSData dataWithContentsOfFile:path1];
[mailer addAttachmentData:myData1 mimeType:@"image/png" fileName:@"photo name"];
NSData *imageData = UIImagePNGRepresentation(self.personimgThumbNail.image);
[mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"Imageone"];
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"png"];
NSData *myData2 = [NSData dataWithContentsOfFile:path2];
[mailer addAttachmentData:myData2 mimeType:@"image/png" fileName:@"photo name"];
NSData *imageDatatwo = UIImagePNGRepresentation(self.personimgThumbNailtwo.image);
[mailer addAttachmentData:imageDatatwo mimeType:@"image/png" fileName:@"Imagetwo"];
NSString *path3 = [[NSBundle mainBundle] pathForResource:@"3" ofType:@"png"];
NSData *myData3 = [NSData dataWithContentsOfFile:path3];
[mailer addAttachmentData:myData3 mimeType:@"image/png" fileName:@"photo name"];
NSData *imageDatathree = UIImagePNGRepresentation(self.personimgThumbNailthree.image);
[mailer addAttachmentData:imageDatathree mimeType:@"image/png" fileName:@"Imagethree"];
NSString *path4 = [[NSBundle mainBundle] pathForResource:@"4" ofType:@"png"];
NSData *myData4 = [NSData dataWithContentsOfFile:path4];
[mailer addAttachmentData:myData4 mimeType:@"image/png" fileName:@"photo name"];
NSData *imageDatafour = UIImagePNGRepresentation(self.personimgThumbNailfour.image);
[mailer addAttachmentData:imageDatafour mimeType:@"image/png" fileName:@"Imagefour"];
NSString *path5 = [[NSBundle mainBundle] pathForResource:@"5" ofType:@"png"];
NSData *myData5 = [NSData dataWithContentsOfFile:path5];
[mailer addAttachmentData:myData5 mimeType:@"image/png" fileName:@"photo name"];
NSData *imageDatafive = UIImagePNGRepresentation(self.personimgThumbNailfive.image);
[mailer addAttachmentData:imageDatafive mimeType:@"image/png" fileName:@"Imagefive"];
NSString *path6 = [[NSBundle mainBundle] pathForResource:@"6" ofType:@"png"];
NSData *myData6 = [NSData dataWithContentsOfFile:path6];
[mailer addAttachmentData:myData6 mimeType:@"image/png" fileName:@"photo name"];
NSData *imageDatasix = UIImagePNGRepresentation(self.personimgThumbNailsix.image);
[mailer addAttachmentData:imageDatasix mimeType:@"image/png" fileName:@"Imagesix"];
NSString *path7 = [[NSBundle mainBundle] pathForResource:@"7" ofType:@"png"];
NSData *myData7 = [NSData dataWithContentsOfFile:path7];
[mailer addAttachmentData:myData7 mimeType:@"image/png" fileName:@"photo name"];
NSData *imageDataseven = UIImagePNGRepresentation(self.personimgThumbNailseven.image);
[mailer addAttachmentData:imageDataseven mimeType:@"image/png" fileName:@"Imageseven"];
NSString *path8 = [[NSBundle mainBundle] pathForResource:@"8" ofType:@"png"];
NSData *myData8 = [NSData dataWithContentsOfFile:path8];
[mailer addAttachmentData:myData8 mimeType:@"image/png" fileName:@"photo name"];
NSData *imageDataeight = UIImagePNGRepresentation(self.personimgThumbNaileight.image);
[mailer addAttachmentData:imageDataeight mimeType:@"image/png" fileName:@"Imageeight"];
NSString *path9 = [[NSBundle mainBundle] pathForResource:@"9" ofType:@"png"];
NSData *myData9 = [NSData dataWithContentsOfFile:path9];
[mailer addAttachmentData:myData9 mimeType:@"image/png" fileName:@"photo name"];
NSData *imageDatanine = UIImagePNGRepresentation(self.personimgThumbNailnine.image);
[mailer addAttachmentData:imageDatanine mimeType:@"image/png" fileName:@"Imagenine"];
NSString *path10 = [[NSBundle mainBundle] pathForResource:@"10" ofType:@"png"];
NSData *myData10 = [NSData dataWithContentsOfFile:path10];
[mailer addAttachmentData:myData10 mimeType:@"image/png" fileName:@"photo name"];
NSData *imageDataten = UIImagePNGRepresentation(self.personimgThumbNailten.image);
[mailer addAttachmentData:imageDataten mimeType:@"image/png" fileName:@"Imageten"];
[self presentModalViewController:mailer animated:YES];
}
}
答案 0 :(得分:0)
我能想到的唯一解释是,如果您将图像编译成一个PDF,并附加PDF。更多关于这一点 -
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName: (NSString*)aFilename
{
// Creates a mutable data object for updating with binary data, like a byte array
NSMutableData *pdfData = [NSMutableData data];
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
UIGraphicsBeginPDFPage();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[aView.layer renderInContext:UIGraphicsGetCurrentContext()];
// remove PDF rendering context
UIGraphicsEndPDFContext();
// Retrieves the document directories from the iOS device
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}