情诗网 >情话短信 > 正文

发短信

来源:情诗网    2021-03-03    分类:情话短信

#import <MessageUI/MessageUI.h>

@interface ViewController ()< MFMessageComposeViewControllerDelegate >

- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    if ([MFMessageComposeViewController canSendText]) {
        
        MFMessageComposeViewController *mc =[[MFMessageComposeViewController alloc]init];
        mc.messageComposeDelegate=self;
        mc.body=@"你好";
        mc.recipients=[NSArray arrayWithObjects:@"10086", nil];
        [self presentViewController:mc animated:YES completion:nil];
        
    }else{
        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"error" message:@"the current can not send SMS"
                                                     delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
}


- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    
    switch (result) {
            
        case MessageComposeResultCancelled:
            NSLog(@"cancell");
            break;
        case MessageComposeResultFailed:
            NSLog(@"failed");
            break;
        case MessageComposeResultSent:
            NSLog(@"sent");
            break;
        default:
            break;
    }
}

热门文章