- (void)showMessageViewWithTel:(NSString *)tel
{ if( [MFMessageComposeViewController canSendText] ){ MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc]init]; //autorelease]; controller.recipients = [NSArray arrayWithObject:tel];
controller.body = @"";
controller.messageComposeDelegate = self; [self presentViewController:controller animated:YES completion:nil]; [[[[controller viewControllers] lastObject] navigationItem] setTitle:@"测试短信"];//修改短信界面标题
}else{ [self alertWithTitle:@"提示信息" msg:@"设备没有短信功能"];
}
} //MFMessageComposeViewControllerDelegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{ [controller dismissViewControllerAnimated:NO completion:nil];//关键的一句 不能为YES switch ( result ) { case MessageComposeResultCancelled: [self alertWithTitle:@"提示信息" msg:@"发送取消"];
break;
case MessageComposeResultFailed:// send failed
[self alertWithTitle:@"提示信息" msg:@"发送失败"];
break;
case MessageComposeResultSent:
[self alertWithTitle:@"提示信息" msg:@"发送成功"];
break;
default:
break;
}
} - (void) alertWithTitle:(NSString *)title msg:(NSString *)msg { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:msg
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"确定", nil]; [alert show]; }