I am writing an enterprise client/server application. The client is an iOS app which uses Cocoa Lumberjack to create the log files. These files will be essential for client debugging and troubleshooting. The file will be a maximum of 1MB, although making it smaller is an option.
I planned to code a "email log file" button but I can't figure out how to send it as an attachment. I suppose I could stuff the email's body with all my log messages, but that seems a bit ugly. What if I want to compress the file into a non-text format before sending开发者_StackOverflow? I've also considered creating a web service to upload the log file to the server but this seems like a lot of work, as I would then need to sort out who's log file is who's and have some kind of purge to keep it neat, etc.
Surely I'm not the first to face this issue. How is everyone else doing this?
Thanks in advance for any help you can give me.
Here's some complete working code that creates an email, adds a HTML body, adds a text attachment, and sends shows the compose view.
Make sure you also define path for resource.
NSData *textData = [[self getEmailAttachment] dataUsingEncoding:NSUTF8StringEncoding];
NSString *htmlData = [self getEmailBodyHTML];
/* Set up the mail compose view and put in the body/attachment */
MFMailComposeViewController *mailComposer = [[[MFMailComposeViewController alloc] init] autorelease];
[mailComposer setMessageBody:htmlData isHTML:NO];
[mailComposer addAttachmentData:textData mimeType:@"text/plain" fileName:@"logfile.txt"];
/* Set default subject */
[mailComposer setSubject:@"Email subject"];
mailComposer.mailComposeDelegate = self;
[self presentModalViewController:mailComposer animated:YES];
精彩评论