简体   繁体   English

在这种情况下,为 iOS 中的 MFMessageComposeController 触发 MessageComposeResultFailed?

[英]At which case the MessageComposeResultFailed is fired for MFMessageComposeController in iOS?

The didFinishWithResult delegate method of MFMessageComposeViewController shows that the message has been sent successfully, even when the device is in airplane mode or when the device has no SIM,but the message sending is failed .The delegate does not go through the failure state.Why doesnt it go to failure state?.Please give me some suggestion on this. MFMessageComposeViewController的didFinishWithResult委托方法显示消息发送成功,即使设备处于飞行模式或设备没有SIM卡,但消息发送失败。委托没有go通过失败state。为什么没有它 go 到故障 state?请给我一些建议。 The code is given as below:代码如下:

   - (void)displaySMSComposerSheet 
{
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
    picker.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.
    picker.body = @"Hello from California!";
    
    [self presentViewController:picker animated:YES completion:NULL];
}

And the DELEGATE methods are given below: 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
{
    self.feedbackMsg.hidden = NO;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MessageComposeResultCancelled:
            self.feedbackMsg.text = @"Result: SMS sending canceled";
            break;
        case MessageComposeResultSent:
            self.feedbackMsg.text = @"Result: SMS sent";
            break;
        case MessageComposeResultFailed:
            self.feedbackMsg.text = @"Result: SMS sending failed";
            break;
        default:
            self.feedbackMsg.text = @"Result: SMS not sent";
            break;
    }
    
    [self dismissViewControllerAnimated:YES completion:NULL];
}

For me when I press "CANCEL" or "SEND" message the correct delegates are fired.对我来说,当我按下“取消”或“发送”消息时,正确的代表会被解雇。 But when I switch ON the AIRPLANE Mode or the device with no SIM still the MessageComposeResultSent Is fired.但是,当我打开 AIRPLANE 模式或没有 SIM 卡的设备时,仍然会触发MessageComposeResultSent Can some one tell clearly when the MessageComposeResultFailed is fired?有人可以清楚地知道MessageComposeResultFailed何时被触发吗? Any live steps?有直播步骤吗? Please kindly help me请帮助我

This behavior makes sense based on the docs for MessageComposeResult :根据MessageComposeResult的文档,这种行为是有意义的:

case sent
   The user successfully queued or sent the message.

The delegate method can report MessageComposeResultSent even if all your app did was give the message to the system to send.委托方法可以报告MessageComposeResultSent ,即使您的应用所做的只是将消息发送给系统。 It's not a guarantee that it actually sent the message.不能保证它确实发送了消息。

The docs aren't clear about when it reports MessageComposeResultFailed , but I imagine it's meant to capture any possible error that could occur.文档不清楚何时报告MessageComposeResultFailed ,但我想它是为了捕获可能发生的任何可能的错误。

Depending on your particular use case, you could add an check for cellular connectivity before allowing someone to use MFMessageComposeViewController .根据您的特定用例,您可以在允许某人使用MFMessageComposeViewController之前添加对蜂窝连接的检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM