ios - 在哪种情况下,iOS 中的 MFMessageComposeController 会触发 MessageComposeResultFailed?

标签 ios objective-c iphone xcode mfmessagecomposeviewcontroller

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

    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];
}

对我来说,当我按“取消”或“发送”消息时,正确的代表将被解雇。但是,当我打开飞机模式或没有 SIM 卡的设备时,MessageComposeResultSent 仍然会被触发。有人可以清楚地告诉 MessageComposeResultFailed 何时被触发吗?有现场脚步吗?请帮助我

最佳答案

根据docs for MessageComposeResult,此行为是有意义的:

case sent
   The user successfully queued or sent the message.

即使您的应用所做的只是将消息发送给系统,委托(delegate)方法也可以报告 MessageComposeResultSent。这并不能保证它确实发送了消息。

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

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

关于ios - 在哪种情况下,iOS 中的 MFMessageComposeController 会触发 MessageComposeResultFailed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65739559/

相关文章:

iOS - UIView 不显示在 UIStackView 内

IOS Objective-c : Class NSObject derived is released but memory start increase

iphone - 当 webview 大于屏幕时,将 UIWebview 内容转换为 UIImage

ios - 复杂的交叉布局架构和关注点分离

ios - iOS "mobile web app"中的 location.reload(true) 在 safari 中重新打开

ios - 在 map View 中显示动态注释图钉

iphone - IOS - 通过使用 ARC 的循环创建新的对象实例

iphone - 当我将触摸事件传递给 super View 时,MyScrollView 不响应触摸

ios - UIImagePickerController 允许我拍摄照片和视频,但不允许我保存它们或 "use"它们

ios - Swift 中的 UITableView – 未知异常