我想允许用户发送应用程序崩溃日志文件的电子邮件。问题是,从我的设备,我能够发送日志文件作为电子邮件的附件。但是从某些设备我收到电子邮件但没有附加的日志文件。 我使用以下代码发送电子邮件日志文件。
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Application Logs File"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"my Email ID", nil];
[mailer setToRecipients:toRecipients];
NSData *fileData = [NSData dataWithContentsOfFile:[Utility getCurrentLogsFileNameFromUserDefaults]];
NSString* theFileName = [[Utility getCurrentLogsFileNameFromUserDefaults] lastPathComponent];
NSLog(@"File Data %@",theFileName);
[mailer addAttachmentData:fileData mimeType:@"text/x-log" fileName:theFileName];
NSString *emailBody = @"PFA for logs file.";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}