iOS发送短信功能
1、程序外发短信
NSString *phoneStr = @"10086";2、程序内发短信,发完短信自动返回应用
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"sms://%@", phoneStr]];
[[UIApplication sharedApplication] openURL:url];
首先导入框架MessageUI.framework
引入头文件 #import
实现代理方法
3、直接上代码
+ (void)sendShortMessageWithPhoneNumber:(NSString *)phoneNumber text:(NSString *)text viewController:(BaseViewController *)viewController {【iOS发送短信功能】Demo地址:https://github.com/jayZhangh/PhotosFrameworkBasicUsage.git
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
// 发送短信的号码,数组形式入参
controller.recipients = @[phoneNumber];
controller.navigationBar.tintColor = [UIColor redColor];
// 此处的body就是短信将要发生的内容
controller.body = text;
controller.messageComposeDelegate = viewController;
[viewController presentViewController:controller animated:YES completion:nil];
// 修改短信界面标题
[[[[controller viewControllers] lastObject] navigationItem] setTitle:@"title"];
} else {
[BaseViewController hudWithTitle:@"该设备不支持短信功能"];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
[controller dismissViewControllerAnimated:YES completion:nil];
switch (result) {
case MessageComposeResultSent:
[BaseViewController hudWithTitle:@"信息传送成功"];
break;
case MessageComposeResultFailed:
[BaseViewController hudWithTitle:@"信息传送失败"];
break;
case MessageComposeResultCancelled:
[BaseViewController hudWithTitle:@"信息被用户取消发送"];
break;
default:
break;
}
}
推荐阅读
- 2020-04-07vue中Axios的封装和API接口的管理
- python学习之|python学习之 实现QQ自动发送消息
- iOS中的Block
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- 2019-08-29|2019-08-29 iOS13适配那点事
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- iOS面试题--基础
- 接口|axios接口报错-参数类型错误解决
- iOS|iOS 笔记之_时间戳 + DES 加密
- iOS,打Framework静态库