问题描述
MFMessageComposeViewController的didFinishWithResult委托方法显示消息已经发送成功,即使设备处于飞行模式或设备没有SIM卡,但消息发送失败。委托不通过失败状态。为什么不进入失败状态?。请给我一些建议。代码如下:
- (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];
}
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];
}
对我来说,当我按下“取消”或“发送”消息时,会触发正确的代表。但是当我打开飞机模式或没有 SIM 卡的设备时,MessageComposeResultSent
仍然会被触发。有人能清楚地告诉 MessageComposeResultFailed
何时被触发吗?有实时步骤吗?请帮助我
解决方法
这种行为基于 docs for MessageComposeResult
:
Test_1.sas7bdat
Tes_2.sas7bdat
Hive external table - partition 1 - Test_1.sas7bdat,Partition 2 - Test_2.sas7bdat
委托方法可以报告 case sent
The user successfully queued or sent the message.
,即使您的应用程序所做的只是向系统发送消息。不能保证它确实发送了消息。
文档不清楚何时报告 MessageComposeResultSent
,但我想它是为了捕获可能发生的任何可能的错误。
根据您的特定用例,您可以在允许某人使用 MessageComposeResultFailed
之前添加对蜂窝网络连接的检查。