ios从app发送图像到邮件客户端不显示

时间:2013-05-30 11:29:40

标签: ios image file

我想在我的应用程序上打开本机邮件客户端并发送以下内容:

NSString *subject = [NSString stringWithFormat:@"%@", self.selectedProposal.title];

NSString *mail = [NSString stringWithFormat:@""];

NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation( self.logoImageView.image )];
CreditCalculatorModel *model = [CreditCalculatorModel tlSharedInstance];
NSString *emailBody = @"";
emailBody = [emailBody stringByAppendingString:[NSString stringWithFormat:@"<p><center><img src='data:image/png;base64,%@'></center></p>", [imageData base64EncodedString]]];
emailBody = [emailBody stringByAppendingFormat:@"<p><center><h4>%@</h4></center></p>", self.selectedProposal.title];
emailBody = [emailBody stringByAppendingString:@"<br />"];
emailBody = [emailBody stringByAppendingString:self.amountLabel.text];
emailBody = [emailBody stringByAppendingString:@"<br />"];
emailBody = [emailBody stringByAppendingString:self.initialLabel.text];
emailBody = [emailBody stringByAppendingString:@"<br />"];
emailBody = [emailBody stringByAppendingString:self.creditAmountLabel.text];
emailBody = [emailBody stringByAppendingString:@"<br />"];
emailBody = [emailBody stringByAppendingFormat:@"Процентная ставка: %@", self.rateLabel.text];
emailBody = [emailBody stringByAppendingString:@"<br />"];
emailBody = [emailBody stringByAppendingFormat:@"Эффективная ставка: %@", self.efficientRateLabel.text];
emailBody = [emailBody stringByAppendingString:@"<br />"];
emailBody = [emailBody stringByAppendingFormat:@"Ежемесячный платёж: %@", self.paymentLabel.text];
emailBody = [emailBody stringByAppendingString:@"<br />"];
emailBody = [emailBody stringByAppendingFormat:@"Переплата по кредиту: %@", self.overheadLabel.text];
emailBody = [emailBody stringByAppendingString:@"<br />"];
emailBody = [emailBody stringByAppendingString:@"<br /></h5>График платежей</h5><br />"];
emailBody = [emailBody stringByAppendingString:@"<table border='1'>"];
emailBody = [emailBody stringByAppendingString:@"<tr><td>Месяц</td><td>Задолженность</td><td>Платёж</td></tr>"];
for ( int i = 0; i < model.term; i++ )
{
    emailBody = [emailBody stringByAppendingFormat:@"<tr><td>%d</td><td>%@ р.</td><td>%@ р.</td></tr>",
                 i + 1,
                 [self.unicomDecimalNumberFormatter stringFromNumber:@((int) [CreditCalculatorModel deptForMonth:i
                                                                                                        withRate:[self.selectedProposal.rate doubleValue]/100
                                                                                                       andAmount:model.amount
                                                                                                         andTerm:model.term
                                                                                                      andInitial:model.initial
                                                                                                      andAnnuity:!self.selectedProposal.payment_type])],
                 [self.unicomDecimalNumberFormatter stringFromNumber:@((int) [CreditCalculatorModel paymentForMonth:i
                                                                                                           withRate:[self.selectedProposal.rate doubleValue]/100
                                                                                                          andAmount:model.amount
                                                                                                            andTerm:model.term
                                                                                                         andInitial:model.initial
                                                                                                         andAnnuity:!self.selectedProposal.payment_type])]
                 ];
}
emailBody = [emailBody stringByAppendingString:@"</table>"];






NSString *recipients = @"mailto:?to=";

NSString *subjectMessage = [NSString stringWithFormat:@"&subject=%@", subject];

NSString *bodyMessage = [NSString stringWithFormat:@"&body=%@", emailBody];

NSString *email = [NSString stringWithFormat:@"%@%@%@", recipients, subjectMessage, bodyMessage];

email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];

除了图像表示外,一切都还可以。它没有显示。在图像的位置只出现一个小的空矩形。 电话选项中的图像表示为ON。 我无法使用MFMailComposeViewController执行此任务。 感谢帮助

1 个答案:

答案 0 :(得分:0)

尝试这种方法:

    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    mailer.mailComposeDelegate = self;
    [mailer setSubject:@"Message"];
    NSArray *toRecipients = [NSArray arrayWithObjects:@"fisrtMail@example.com", @"secondMail@example.com", nil];
    [mailer setToRecipients:toRecipients];
    UIImage *myImage = [UIImage imageNamed:@"yourImage.png"];
    NSData *imageData = UIImagePNGRepresentation(myImage);
    [mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"mobiletutsImage"];
    NSString *emailBody = @"your email body";
    [mailer setMessageBody:emailBody isHTML:NO];
    [self presentModalViewController:mailer animated:YES];
    [mailer release];