I’m creating an app that lets users take and store photos in a Core Data graph, then email these photos in a table from within the app.
I’ve been able to save the photos within the SQlite database by converting the asset paths to NSURL values and referencing them – to stop the database from suffering from memory issues.
My last task is to allow users to email their photos in a nicely laid out table, complete with a description of the photo. This is automatically generated from the UITableView that the images are displayed in.
I’m using the following to generate the HTML email:
- (NSString *)generateHTMLBody {
NSString *res = @"<HTML><body><table border=""1"">\n";
for (int i=0; i < [self.fetchedResultsController.fetchedObjects count]; i++) {
NSString *rowCount = [NSString stringWithFormat:@"%d.", i+1];
NSString *tmp = (NSString *)[imageList objectAtIndex:0];
NSString *imageString = [NSString stringWithFormat:@"<img src=""%@"" />",tmp];
res = res = [res stringByAppendingString:@"<tr><td>"];
res = res = [res stringByAppendingString:rowCount];
res = res = [res stringByAppendingString:@"</td>\n"];
res = res = [res stringByAppendingString:@"<td>"];
res = res = [res stringByAppendingString:imageString];
res = res = [res stringByAppendingString:@"</td>\n"];
res = res = [res stringByAppendingString:@"<td>"];
res = res = [res stringByAppendingString:tmp];
res = res = [res stringByAppendingString:@"</td></tr>\n"];
}
res = [res stringByAppendingString:@"</table></body></html>\n"];
return res;
}
What I’m trying to do is load the images from the Core Data graph into an HTML img tag. I’m pulling the following asset path into the var tmp:
assets-library://asset/asset.JPG?id=2F62642E-00B3-4D85-82D2-A6A1F064F2CE&ext=JPG
However, this isn’t working. How would I load these photos into the email?
How are you sending the email? Via a
MFMailComposeViewController? I would have thought that you’d be attaching files viaaddAttachmentData:mimeType:fileName:. That’s probably easiest.Alternatively, if you want to build a custom, pretty html body with images included in there, you probably want to pursue a base64 encoding of your images. You then put something like
<img src="data:image/gif;base64,XXX">in your html, whereXXXis the base64 encoding of your image. When I did this, I encoded using Google GTMBase64 in GTM:http://code.google.com/p/google-toolbox-for-mac/
There are also articles here about base64 libraries, e.g.
How do I do base64 encoding on iphone-sdk?