![](/img/trans.png)
[英]MessageComposeResultFailed When this case fire below code
[英]At which case the MessageComposeResultFailed is fired for MFMessageComposeController in iOS?
MFMessageComposeViewController的didFinishWithResult委托方法顯示消息發送成功,即使設備處於飛行模式或設備沒有SIM卡,但消息發送失敗。委托沒有go通過失敗state。為什么沒有它 go 到故障 state?請給我一些建議。 代碼如下:
- (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];
}
對我來說,當我按下“取消”或“發送”消息時,正確的代表會被解雇。 但是,當我打開 AIRPLANE 模式或沒有 SIM 卡的設備時,仍然會觸發MessageComposeResultSent
。 有人可以清楚地知道MessageComposeResultFailed
何時被觸發嗎? 有直播步驟嗎? 請幫助我
根據MessageComposeResult
的文檔,這種行為是有意義的:
case sent
The user successfully queued or sent the message.
委托方法可以報告MessageComposeResultSent
,即使您的應用所做的只是將消息發送給系統。 不能保證它確實發送了消息。
文檔不清楚何時報告MessageComposeResultFailed
,但我想它是為了捕獲可能發生的任何可能的錯誤。
根據您的特定用例,您可以在允許某人使用MFMessageComposeViewController
之前添加對蜂窩連接的檢查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.