IOS 掉用系统发短信


#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];
}

 

posted @ 2014-03-30 14:33  菜鸟程序猿  阅读(334)  评论(0编辑  收藏  举报