美文网首页
IOS发送短信

IOS发送短信

作者: 夏末秋刀鱼 | 来源:发表于2019-12-09 21:00 被阅读0次

导入头文件

#import <MessageUI/MessageUI.h>

调用方法

if ([MFMessageComposeViewController canSendText]) {
        
        //  判断一下是否支持发送短信,比如模拟器
        MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];
        messageVC.recipients = @[@"10086"]; //需要发送的手机号数组
        
        messageVC.body = @"短信内容短信内容短信内容短信内容短信内容";
        messageVC.modalPresentationStyle = UIModalPresentationFullScreen;
        messageVC.messageComposeDelegate = self; //指定代理
        [vc presentViewController:messageVC animated:YES completion:nil];
    } else {
        [PublicHUD showStateText:@"设备不支持短信功能"];
    }

代理方法

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    if (result == MessageComposeResultCancelled) {
        [controller dismissViewControllerAnimated:YES completion:nil];
    } else if (result == MessageComposeResultFailed) {
        [controller dismissViewControllerAnimated:YES completion:^{
            [PublicHUD showStateText:@"邀请发送失败,请稍后重试"];
            
        }];
    } else {
        [controller dismissViewControllerAnimated:YES completion:^{
            [PublicHUD showStateText:@"邀请发送成功"];
        }];
    }
}

相关文章

网友评论

      本文标题:IOS发送短信

      本文链接:https://www.haomeiwen.com/subject/tqvigctx.html