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