iOS:点击消息应用中的取消返回到调用它的应用

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

我们的团队经理提出了以下想法:在我们的应用中,当用户点击 Send Msg 按钮时,我们的应用会打开消息应用。我们的经理想要点击 Cancel 返回我们的应用程序(请参见下面的屏幕截图),而不是状态栏中左上角的 Go back to ... 快捷方式。这可能吗?

这是图片:

UPDATE messageComposeViewController委托方法是这样的,我dismiss 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];
}

这是我的 viewWillAppear 方法:

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

如果你是在外部打开消息编辑器,也就是说,你只是打开默认的消息应用程序(我想这就是正在发生的事情,否则左上角不会有返回按钮),不幸的是我单击 Cancel 按钮时,我不知道有什么方法可以返回到您的应用程序。

但是,如果您正在使用 MFMessageComposeViewController,这可能是个好主意,因为您的用户不必离开您的应用程序,当用户选择 [=13] 时,绝对可以采取相应的行动=].

你可以看看 Apple 的文档 here,它利用了 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];
}

按照 Stephenye 所说的,如果您使用 MFMessageComposeViewController,取消按钮将允许您返回到您的应用程序(无论如何您仍然会在您的应用程序中,因为您在显示任何其他视图控制器时显示消息控制器) .

这是一个例子:

-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    switch (result)
    {
        [controller dismissViewControllerAnimated:YES completion:^{
            case MessageComposeResultCancelled:
                break;
            case MessageComposeResultFailed:
                [LMLSendResultAlert showSuccessOrFail:0 withSuccesString:@"" andFailStr:@"短信发送失败" needPopOrdismiss:0 complete:nil];
                break;
            case MessageComposeResultSent:
                break;
            default:
                break;
        }
        }];

}

-(void)presentMessagerOnViewController:(UIViewController*)controller
{
    if(![MFMessageComposeViewController canSendText])
    {
        //show error message
        return;
    }

    NSArray *recipients = @[@"0424456654"];
    NSString *defaulMessage = @"You should absolutely upvote my answer";

    MFMessageComposeViewController *composer = [[MFMessageComposeViewController alloc] init];
    composer.messageComposeDelegate = self;
    [composer setRecipients: recipients];
    [composer setBody: defaulMessage];
    [self presentViewController: composer animated:YES completion: NULL];
}