在哪种情况下,MessageComposeResultFailed在iOS中为MFMessageComposeContr



MFMessageComposeViewController的didFinishWithResult委托方法显示消息已成功发送,即使当设备处于飞行模式或设备没有SIM卡时,但消息发送失败委托不经过失败状态。为什么它没有进入故障状态?请给我一些建议。代码如下:

    MFMessageComposeViewController *pic = [[MFMessageComposeViewController alloc] init];
    pic.messageComposeDelegate = self;
    
    // You can specify one or more preconfigured recipients.  The user has
    // the option to remove or add recipients from the message composer view
    // controller.
    /* picker.recipients = @[@"Phone number here"]; */
    
    // You can specify the initial message text that will appear in the message
    // composer view controller.
    pic.body = @"Hello from California!";
    
    [self presentViewController:pic animated:YES completion:NULL];
}

和DELEGATE的方法如下:

  // -------------------------------------------------------------------------------
//  messageComposeViewController:didFinishWithResult:
//  Dismisses the message composition interface when users tap Cancel or Send.
//  Proceeds to update the feedback message field with the result of the
//  operation.
// -------------------------------------------------------------------------------
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller 
              didFinishWithResult:(MessageComposeResult)result
{
    
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MessageComposeResultCancelled:
//Cancelled
            break;
        case MessageComposeResultSent:
//Sent
            break;
        case MessageComposeResultFailed:
//Failed
            break;
        default:
            
            break;
    }
    
    [self dismissViewControllerAnimated:YES completion:NULL];
}

当我按下&;取消&;或";SEND"消息,将触发正确的委托。但是当我打开飞行模式或没有SIM卡的设备时,MessageComposeResultSent仍然被触发。有人能清楚地说出MessageComposeResultFailed是什么时候发射的吗?有活的步骤吗?请帮帮我

这个行为是有意义的基于MessageComposeResult的文档:

case sent
   The user successfully queued or sent the message.

委派方法可以报告MessageComposeResultSent,即使你的应用程序所做的是给系统发送的消息。这并不能保证它确实发送了消息。

文档不清楚何时报告MessageComposeResultFailed,但我想它是为了捕获任何可能发生的错误。

根据您的特定用例,您可以在允许某人使用MFMessageComposeViewController之前添加蜂窝连接检查。