Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [solved] Qt 5.4: Send E-Mai with attachment on iOS

    Mobile and Embedded
    2
    6
    1879
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      nando76 last edited by

      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

      1 Reply Last reply Reply Quote 0
      • N
        nando76 last edited by

        Got it working with this code change:
        @
        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:picker animated:NO completion:nil];
        @

        Greetings Nando

        1 Reply Last reply Reply Quote 0
        • L
          lynic last edited by

          How did you manager to close the MFMailComposeViewController (e.g. when "didFinishWithResult" is called)?

          1 Reply Last reply Reply Quote 0
          • L
            lynic last edited by

            How did you manager to close the MFMailComposeViewController (e.g. when "didFinishWithResult" is called)?

            1 Reply Last reply Reply Quote 0
            • N
              nando76 last edited by

              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]

              1 Reply Last reply Reply Quote 0
              • N
                nando76 last edited by

                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]

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post