0

在我的应用程序中,我使用MFMessageComposeViewController发送消息。以下代码是我用来发送消息的示例

        MFMessageComposeViewController *msgController = [[[MFMessageComposeViewController alloc] init] autorelease];
        if([MFMessageComposeViewController canSendText])
        {
            msgController.messageComposeDelegate = self;
            msgController.body = [NSString stringWithFormat:@"%@", appDelegate.finalConactStr ];
            [self presentModalViewController:msgController animated:YES];
        }

并使用以下代码检查结果

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result 
{
    switch (result)
    {
    case MessageComposeResultCancelled:
        cancelAlert = [[UIAlertView alloc] initWithTitle:@"SMS a Contact" message:@"Cancelled"delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [cancelAlert show];
        [cancelAlert release];
        NSLog(@"Result: canceled");
        break;
    case MessageComposeResultSent:
        successAlert = [[UIAlertView alloc]initWithTitle:@"SMS a Contact" message:@"Successfully sent" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [successAlert show];
        [successAlert release];
        NSLog(@"Result: sent");
        break;
    case MessageComposeResultFailed:
        failAlert = [[UIAlertView alloc]initWithTitle:@"SMS a Contact" message:@"Failed" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [failAlert show];
        [failAlert release];

        NSLog(@"Result: failed");
        break;
    default:
        notSentAlert = [[UIAlertView alloc]initWithTitle:@"SMS a Contact" message:@"Not Sent" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [notSentAlert show];
        [notSentAlert release];

        NSLog(@"Result: not sent");
        break;
    }
    [self dismissModalViewControllerAnimated:YES];
 }

但没有 sim 它也显示像成功发送一样的警报

我们如何检查设备是否有 sim 卡或消息发送功能是否存在。任何人都可以帮助或建议我。

提前致谢。

4

1 回答 1

0

由于 Apple 推出了 iMessage,所有可以运行 iOS5 的设备都可以通过MFMessageComposeViewController.

因此,无需检查设备中是否安装了 sim,只需相信[MFMessageComposeViewController canSendText]设备会告诉您设备是否可以发送消息。

  • MessageComposeResultCancelled:用户取消了合成。
  • MessageComposeResultSent:用户成功排队或发送消息。
  • MessageComposeResultFailed: 用户尝试保存或发送消息失败。
于 2012-06-21T09:35:44.597 回答