实现在ios开发中cocoalumberjack发送log email ,这是我转载的,原文:http://ios.662p.com/thread-148-1-1.html
- (NSMutableArray *)errorLogData { NSUInteger maximumLogFilesToReturn = MIN([KRLogManager sharedInstance].fileLogger.logFileManager.maximumNumberOfLogFiles, 10); NSMutableArray *errorLogFiles = [NSMutableArray arrayWithCapacity:maximumLogFilesToReturn]; DDFileLogger *logger = [KRLogManager sharedInstance].fileLogger; NSArray *sortedLogFileInfos = [logger.logFileManager sortedLogFileInfos]; for (int i = 0; i < MIN(sortedLogFileInfos.count, maximumLogFilesToReturn); i++) { DDLogFileInfo *logFileInfo = [sortedLogFileInfos objectAtIndex:i]; NSData *fileData = [NSData dataWithContentsOfFile:logFileInfo.filePath]; [errorLogFiles addObject:fileData]; } return errorLogFiles; } - (void)composeEmailWithDebugAttachment { if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init]; mailViewController.mailComposeDelegate = self; NSMutableData *errorLogData = [NSMutableData data]; for (NSData *errorLogFileData in [self errorLogData]) { [errorLogData appendData:errorLogFileData]; } [mailViewController addAttachmentData:errorLogData mimeType:@"text/plain" fileName:@"errorLog.txt"]; [mailViewController setSubject:NSLocalizedString(@"Good Subject", @"");]; [mailViewController setToRecipients:[NSArray arrayWithObject:@"some@email.com"]]; [self presentModalViewController:mailViewController animated:YES]; } else { NSString *message; message = NSLocalizedString(@"Sorry, your issue can't be reported right now. This is most likely because no mail accounts are set up on your iPad.", @""); [[[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles: nil] show]; } }