Reputation: 514
I have read other threads and tried multiple variables.
I have an app that attaches a screenshot to an in-app email.
When I press the send or cancel button the email doesn't dismiss.
Not sure if I have a delegate for this action.
Code:
.h
- (IBAction)openMail: (id)sender;
.m
//Open Mail
- (IBAction)openMail: (id)sender {
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
NSData * imageData = UIImageJPEGRepresentation(viewImage,2.0);
if ([MFMailComposeViewController canSendMail] ) {
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc]
init];
mailComposer.delegate = self;
[mailComposer addAttachmentData:imageData mimeType:@"image/png"
fileName:@"attachment.jpng"];
/* Configure other settings */
[mailComposer setSubject:@""];
[mailComposer setToRecipients:[NSArray arrayWithObjects:@"", nil]];
[mailComposer setToRecipients:[NSArray arrayWithObjects:@"%@", nil]];
[mailComposer setSubject:@"4-4-2 Tactics/Line Up"];
//[mailComposer setMessageBody:AddNotesTextField.text isHTML:NO];
[mailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:mailComposer animated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
if (error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:
[NSString stringWithFormat:@"Error %@", [error description]] delegate:self
cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
newMedia = YES;
}
Upvotes: 0
Views: 1313
Reputation: 86
Maybe you should try this
[self dismissViewControllerAnimated:YES completion:nil];
Upvotes: 1
Reputation: 514
Got it figured out.
Here is what I needed.
//Open Mail
- (IBAction)openMail: (id)sender {
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
NSData * imageData = UIImageJPEGRepresentation(viewImage,2.0);
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
[mailComposer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[mailComposer setToRecipients:[NSArray arrayWithObjects:@"%@", nil]];
[mailComposer setSubject:@"4-4-2 Tactics/Line Up"];
[mailComposer setMessageBody:AddNotesTextField.text isHTML:NO];
[mailComposer addAttachmentData:imageData mimeType:@"image/png" fileName:@"attachment.jpng"];
[mailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:mailComposer animated:YES completion:nil];
}
newMedia = YES;
}
Very subtle change
Upvotes: 1