开发者

iPhone: attaching an image from image picker to email does not display on windows

[SOLVED] Guess I should have RTFM! Using [MFMailComposeViewC开发者_如何学JAVAontroller addAttachmentData: mimeType: fileName:] solved my problem completely. No need for base64 encoding at all :)

For anyone whose interested this question provides some good information about base64 encoding.

I allow the user to take or choose an image and attach it to an email. The email sends and delivers perfectly well in Mac Mail but on Windows (Outlook Express & gmail) the image does not display. Gmail tells me 'The Conversion Cannot Be Loaded'.

Below is the code I use to attach the image to an email. It must eb something to do with the encoding of the image. Can anyone advise?

Many thanks for any help

- (void) createEmail {

// set up the image data.
NSData *imageData = [NSData dataWithData:UIImageJPEGRepresentation(self.imageToUpload, 1.0)];
NSString *base64String = [imageData base64EncodedString];
NSString *emailBodyString = [NSString stringWithFormat:@"<html><body><img src='data:image/jpeg;base64,%@'></body></html>",base64String];

// create the email modal
NSArray *recipients = [[NSArray alloc] initWithObjects:@"test@email.com",nil];

MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
emailDialog.mailComposeDelegate = self;
[emailDialog setToRecipients:recipients];
[emailDialog setSubject:@"Time Sheet Submission from iPhone App"];
[emailDialog setMessageBody:emailBodyString isHTML:YES];

[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
[recipients release];

}


Guess I should have RTFM! Using [MFMailComposeViewController addAttachmentData: mimeType: fileName:] solved my problem completely. No need for base64 encoding at all :)

For anyone whose interested this question provides some good information about base64 encoding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜