- (void)sendMessage {
    if ([MFMessageComposeViewController canSendText]) {
        MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
        self.controller  = controller;
        
        
        //设定SMS讯息内容
        controller.body = [NSString stringWithFormat:@"消息内容"];
        
        //设定接传送对象的号码
        controller.recipients = @[18322222222];
        controller.messageComposeDelegate = self;
        
        [self presentViewController:self.controller animated:YES completion:nil];
        
    } else {
        NSLog(@"您的手机无法送短信");
    }
}


#pragma mark - MFMessageComposeViewControllerDelegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result; {
    
    switch (result) {
        case MessageComposeResultSent:
        {
            NSLog(@"讯息传送成功");
        }
            break;
        case MessageComposeResultFailed:
        {
            NSLog(@"讯息传送失败");
        }
            break;
        case MessageComposeResultCancelled:
        {
            NSLog(@"讯息被用户取消传送");
        }
            break;
            
        default:
            break;
    }
    
    [controller dismissViewControllerAnimated:YES completion:nil];
}

 

posted on 2017-06-22 10:55  fatal-奚山遇白  阅读(171)  评论(0编辑  收藏  举报