0

I've got a problem with my universal app. In particular my problem is about using MessageComposerViewController (MCVC). I want to send email with a pdf attached and all works done. My problem occurs when I dismiss the MessageComposerViewController. Indeed when I remove MCVC from main view I'd like that subviews in mainView continue to has exclusiveTouch tag flagged to true.

This behavior occurs when I run my app on iPad but it doesn't happen when I use iPhone. When I use iPhone device, after I've sent an e-mail (or after I've aborted it) the touch signal is captured by mainview and I don't know the reason.

My hierarchy is:

mainView (GameView) within some subviews that I use to manage file actions: (open file, send file, remove file). To apply the right actions I've linked a UITapGestureRecognizer to the 3 buttons. After MCVC is dismissed, I'd like to continue using the three buttons but I can't.

I post some code:

MCMessageComposerViewController.h:

@interface MessageComposerViewController : UIViewController{
MFMailComposeViewController *mc;}

MCMessageViewController.m:

- (void)mailComposeController:(MFMailComposeViewController*)controller 
        didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
    self.feedbackMsg.hidden = NO;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            self.feedbackMsg.text = @"Result: Mail sending canceled";
            break;
        case MFMailComposeResultSaved:
            self.feedbackMsg.text = @"Result: Mail saved";
            break;
        case MFMailComposeResultSent:
            self.feedbackMsg.text = @"Result: Mail sent";
            break;
        case MFMailComposeResultFailed:
            self.feedbackMsg.text = @"Result: Mail sending failed";
            break;
        default:
            self.feedbackMsg.text = @"Result: Mail not sent";
            break;
    }

    [mc.navigationController popViewControllerAnimated:YES];
    [mc dismissViewControllerAnimated:YES completion:nil];
    [self.view removeFromSuperview];
}

- (void)displayMailComposerSheet:(NSString *)_fileName{
    NSString *pathFile = @"blablablaPath";
    NSString *emailTitle = "blablablaTitle";
    mc = [[MFMailComposeViewController alloc] init];
    mc.mailComposeDelegate = self;
    [mc setSubject:emailTitle];
    // Get the resource path and read the file using NSData
    NSData *fileData;

    while(!fileData){
        fileData = [NSData dataWithContentsOfFile:pathFile];
        if(fileData) break;
        [f_t createPdfWithName:_fileName];}//create pdf file if it isn't exist

    [mc addAttachmentData:fileData mimeType:@"application/pdf" fileName:_fileName];

    [self presentViewController:mc animated:YES completion:NULL];}

GameView.m:

- (void)sendFile:(UITapGestureRecognizer *)recognizer{
    mail = [[MessageComposerViewController alloc] init];
    [self addSubview:mail.view];
    [mail displayMailComposerSheet: fileName];
}

I'd like to post an image but I've not enough reputation to do this...

Please help me!!! :-)

Jack
  • 49
  • 1
  • 5
  • `[self.view removeFromSuperview];` That is illegal and it is amazing that your code "works" on any device at all. – matt May 25 '15 at 13:51
  • Update your question with the code to the `displayMailComposerSheet:` method. – rmaddy May 25 '15 at 14:01
  • @matt It's amazing but if I remove that line, it doesn't work neither on the iPad... – Jack May 25 '15 at 14:58
  • @maddy I've updated the code in the original question. Thanks for your tilme – Jack May 25 '15 at 15:05
  • @user2595042 It's not amazing. That line is _wrong_. You must work with the _view controller_, not directly with the view. – matt May 25 '15 at 15:46
  • Given your updated code, why is `MessageComposeViewController` a view controller? The only reason seems to be so you can present the mail composer. But that's the wrong reason. Your `MessageComposeViewController` is not a view controller (conceptually), it's just a little helper class. – rmaddy May 25 '15 at 18:27

0 Answers0