从iPhone向其他手机发送消息

从iPhone向其他手机发送消息,iphone,ios,Iphone,Ios,在我的应用程序中,我使用MFMessageComposeViewController发送消息。 下面的代码是我用来发送消息的示例 MFMessageComposeViewController *msgController = [[[MFMessageComposeViewController alloc] init] autorelease]; if([MFMessageComposeViewController canSendText]) {

在我的应用程序中,我使用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卡或是否有消息发送功能。 任何人都可以帮助或建议我


提前感谢。

自从苹果推出iMessage以来,所有能够运行iOS5的设备都将能够通过发送消息

因此,不需要真正检查设备中是否安装了sim卡,只需相信会告诉您设备是否可以发送消息

  • messagecomposesultcancelled
    :用户取消了合成
  • MessageComposeResultSent
    :用户已成功排队或发送消息
  • MessageComposeResultFailed
    :用户保存或发送消息的尝试失败

但当我在设备上运行时,它总是显示已成功发送。然后消息已发送,您认为为什么未发送?但没有sim卡,也没有号码也显示已成功发送。由于iMessage,您还可以将消息发送到电子邮件地址(Apple ID)。如果它们失败了,您将无能为力,因为您无法从代码中访问它。向Apple发送错误报告。@rckoenes:检查您犯错误的常量定义。我认为这是一个常数。