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