繁体   English   中英

在 iPhone 上发送短信

[英]Sending an SMS on iPhone

我一直致力于在我的应用程序中实现 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]; 
        }
    }
}   

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM