Skip to content

Instantly share code, notes, and snippets.

@funkydevil
Created March 11, 2015 12:14
Show Gist options
  • Save funkydevil/a394930def3b77e02396 to your computer and use it in GitHub Desktop.
Save funkydevil/a394930def3b77e02396 to your computer and use it in GitHub Desktop.
show mail composer
-(void)showMailComposer
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate = self;
[mailComposeViewController setSubject:@"My subject"];
[mailComposeViewController setMessageBody:@"Please check log file in attachment" isHTML:NO];
NSData *dataToSend = [Logger logFileData];
[mailComposeViewController addAttachmentData:dataToSend mimeType:@"text/plain" fileName:@"logger.txt"];
[self.navigationController presentViewController:mailComposeViewController animated:YES completion:nil];
}
else
{
[[[UIAlertView alloc] initWithTitle:@"Cant send log"
message:@"Sorry, there is no email accounts on this device."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil] show];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;
{
if (result == MFMailComposeResultSent)
{
NSLog(@"It's away!");
[Logger clearLogFile];
}
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment