【问题标题】:Sending an SMS on iPhone在 iPhone 上发送短信
【发布时间】:2011-10-22 15:23:11
【问题描述】:

我一直致力于在我的应用中实现 SMS 消息传递。不幸的是,每当我测试它时,我总是得到默认结果,即使它确实发送了消息并且我在另一端收到了它。我做错了什么,我比较了其他例子,我的看起来一样。 这适用于 iMessage 吗???现在我总是收到它,即使我进入短信并且它会说失败。

// feedback message field with the result of the operation.
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller 
             didFinishWithResult:(MessageComposeResult)result {

    switch (result)
    {
        case MFMailComposeResultCancelled:          

            [self displayStickieUniversalViewControllerTitleString:@"Cancelled" bodyString:@"You cancelled sending the SMS.The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3];

            break;
        case MFMailComposeResultSent:

            [self displayStickieUniversalViewControllerTitleString:@"SMS sent" bodyString:@"Your SMS was sent. The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3];

            break;
        case MFMailComposeResultFailed:
            [self displayStickieUniversalViewControllerTitleString:@"Failed" bodyString:@"Failed to send SMS. The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3];

            break;
        default:
            [self displayStickieUniversalViewControllerTitleString:@"Failed" bodyString:@"Failed to send SMS. The event will be saved in the calendar." buttonString:@"Ok, Save Event" bodyTextSize:12.0f buttonTextLines:3];      
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}

/////

 if (actionClicked == @"smsEvent") {
    if ([attendeesArray count]!=0) {
        NSLog(@"Yes clicked, will send sms confirmation");
        Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));

        if (messageClass != nil) {          
            if ([messageClass canSendText]) {
                [self displaySMSComposerSheet];
            }
            else {  

                 [self displayStickieUniversalViewControllerTitleString:@"Device not configured to send SMS." bodyString:@"The event will be saved in the calendar." buttonString:@"Save Event" bodyTextSize:14.0f buttonTextLines:2]; 

            }
        }
        else {

            [self displayStickieUniversalViewControllerTitleString:@"Device not configured to send SMS." bodyString:@"The event will be saved in the calendar." buttonString:@"Save Event" bodyTextSize:14.0f buttonTextLines:2]; 
        }
    }
}   

【问题讨论】:

  • 尝试检查你的结果到底是什么......default 只是一个包罗万象的案例,如果 switch 参数与任何案例都不匹配,则会执行。
  • 你测试过是否真的可以发送短信吗?文档:在呈现消息组合视图之前,调用 canSendText 类方法以确保正确配置用户的设备。如果 canSendText 方法返回 NO,请不要尝试显示消息组合视图。如果 SMS 传送不可用,您可以通知用户或直接在您的应用程序中禁用 SMS 功能。
  • 我已经在应用程序中有一些东西可以捕捉到它无法发送短信。我如何打印出真正的结果。
  • 我认为我的问题是我的默认值周围没有 {} 括号,但现在它总是说已发送。这适用于 iMessage 吗???
  • 我的版本可以在没有任何更改的情况下与 iMessage 一起使用。

标签: ios objective-c iphone sms mfmessagecomposeview


【解决方案1】:

看起来你使用了错误的枚举,也许与它有关,我的看起来像这样:

switch (result)
{
    case MessageComposeResultCancelled:
        break;
    case MessageComposeResultSent:
        break;
    case MessageComposeResultFailed:
        break;
    default:
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"SMS" message:@"Sending Failed - Unknown Error :-("
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];
        [alert release];
    }

        break;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-07
    • 2014-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多