Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [solved] Qt 5.4: Send E-Mai with attachment on iOS
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 2 Posters 2.2k Views
  • 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 Offline
    N Offline
    nando76
    wrote on last edited by
    #1

    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
    0
    • N Offline
      N Offline
      nando76
      wrote on last edited by
      #2

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

      Greetings Nando

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lynic
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lynic
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nando76
            wrote on last edited by
            #5

            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
            0
            • N Offline
              N Offline
              nando76
              wrote on last edited by
              #6

              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
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved