[solved] Qt 5.4: Send E-Mai with attachment on iOS
-
Hi,
like on Android i now want to implement native iOS code to send an e-mail with a file attached.
What i tried is the following:
Create an objective c interface:
@
@interface Mailer : UIViewController <MFMailComposeViewControllerDelegate>
{}
- (void) dealloc;
- (void) sendMailWithAttachment: (NSString*) filename inView: (UIView*) uiview;
- (void) mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error;
@end
-
(void) sendMailWithAttachment: (NSString*) filename inView: (UIView*) uiview;
{
NSLog(@"Mailer:sendMailWithAttachment: create MFMailComposeViewController");// [view addSubview: self];
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Check out this image!"];// Fill out the email body text
NSString *emailBody = @"My cool image is attached";
[picker setMessageBody:emailBody isHTML:NO];[self presentModalViewController:picker animated:YES];
[picker release];
}
@
The code gets called but i get the error:
@
Warning: Attempt to present <MFMailComposeViewController: 0x7ef9e7e0> on <Mailer: 0x7ef91720> whose view is not in the window hierarchy!
@Any ideas how to solve this issue?
Or maybe there is an easier way on iOS to send a mail with attachment?
Greetings
Nando -
Yes,
this is my didFinishWithResult method:@- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Result: canceled");
break;
case MFMailComposeResultSaved:
NSLog(@"Result: saved");
break;
case MFMailComposeResultSent:
NSLog(@"Result: sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Result: failed");
break;
default:
NSLog(@"Result: not sent");
break;
}[self dismissViewControllerAnimated:YES completion:NULL]; //[[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:YES completion:nil];
}@
Hope it helps...
Greetings
Nando[quote author="lynic" date="1423484455"]How did you manager to close the MFMailComposeViewController (e.g. when "didFinishWithResult" is called)? [/quote]
-
Yes,
this is my didFinishWithResult method:@- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Result: canceled");
break;
case MFMailComposeResultSaved:
NSLog(@"Result: saved");
break;
case MFMailComposeResultSent:
NSLog(@"Result: sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Result: failed");
break;
default:
NSLog(@"Result: not sent");
break;
}[self dismissViewControllerAnimated:YES completion:NULL]; //[[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:YES completion:nil];
}@
Hope it helps...
Greetings
Nando[quote author="lynic" date="1423484455"]How did you manager to close the MFMailComposeViewController (e.g. when "didFinishWithResult" is called)? [/quote]