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/