#import <MessageUI/MessageUI.h>
MFMessageComposeViewControllerDelegate
#pragma mark - 调用ios系统短信发送模块
-(void)shareUseSMSWithMessage:(NSString *)message
{
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if (messageClass != nil) {
// Check whether the current device is configured for sending SMS messages
if ([messageClass canSendText]) {
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.body = message;
[self.navigationController presentViewController:picker animated:YES completion:nil];
}
else {
UIAlertView *canSend = [[UIAlertView alloc] initWithTitle:@"设备没有短信功能" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"关闭", nil];
[canSend show];
}
}else{
UIAlertView *visionAlert = [[UIAlertView alloc] initWithTitle:@"iOS版本过低,iOS4.0以上才支持程序内发送短信" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"关闭", nil];
[visionAlert show];
}
} #pragma mark - MFMessageComposeViewControllerDelegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result)
{
case MessageComposeResultCancelled:
NSLog(@"Result: SMS sending canceled");
break;
case MessageComposeResultSent:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"短信发送成功" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
[alert show];
NSLog(@"Result: SMS sent");
}
break;
case MessageComposeResultFailed:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"短信发送失败" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
[alert show];
}
break;
default:
NSLog(@"Result: SMS not sent");
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}