Search code examples
iosmessagecancel-button

iOS: Tap cancel in Messages app to go back to app that invoked it


Our team manager has proposed the following idea: within our app, when a user taps a Send Msg button, our app opens up the Messages app. Our manager wants to tap Cancel to go back to our app (see screenshot below), instead of the top left Go back to ... shortcut in the status bar. Is that possible?

This is the picture: red frame show

UPDATE The messageComposeViewController delegate method is like this, and I see some shaking when I dismiss the message controller?:****

#pragma mark - sms delegate

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
                 didFinishWithResult:(MessageComposeResult)result {

    switch (result)
    {
        case MessageComposeResultCancelled:

            break;
        case MessageComposeResultSent:

            break;
        case MessageComposeResultFailed:

            [LMLSendResultAlert showSuccessOrFail:0 withSuccesString:@"" andFailStr:@"短信发送失败" needPopOrdismiss:0 complete:nil];
            break;
        default:

            break;
    }
    [controller dismissViewControllerAnimated:YES completion:NULL];
}

This is my viewWillAppear method:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setHidden:YES];
}

Solution

  • If you are opening the message editor externally, that is, you just open the default Message app (I guess this is what is happening, otherwise there wouldn't be the Back button at top left corner), unfortunately I'm not aware of any way to go back to your app when clicking the Cancel button.

    However, if you are using MFMessageComposeViewController, which probably is a good idea as your users don't have to leave your app, it would be definitely possible to act accordingly when users choose to cancel.

    You can take a look at Apple's doc here, which utilizes mailComposeController:didFinishWithResult:error:

    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller
                 didFinishWithResult:(MessageComposeResult)result {
       // Check the result or perform other tasks.
    
       // Dismiss the mail compose view controller.
       [self dismissViewControllerAnimated:YES completion:nil];
    }