[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];
- (void)showSMSPicker:(id)sender
{
/**
您必须检查当前设备是否可以在尝试创建一个MFMessageComposeViewController的实例之前发送短信
。 如果设备无法发送短信,
[[MFMessageComposeViewController alloc] init]将返回nil。 您的应用程式用一个空视图控制器调用
-presentViewController时会导致崩溃。
**/
if ([MFMessageComposeViewController canSendText])
// The device can send email.
{
[self displaySMSComposerSheet];
}
else
// The device can not send email.
{
self.feedbackMsg.hidden = NO;
self.feedbackMsg.text = @"Device not configured to send SMS.";
}
}
- (void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
//您可以指定一个或多个预配置的收件人。 用户有从消息编辑器视图中删除或添加收件人的选项控制器
//您可以指定将出现在消息编辑器视图控制器中的初始消息文本。
picker.recipients = @[@"Phone number here"];//发短信的手机号码的数组,数组中是一个即单发,多个即群发。
picker.body = @"Hello from California!"; //短信主体内容
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(140, 100, 100, 100)];
button.backgroundColor = [UIColor blackColor];
[button setTitle:@"发送短信" forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(showSMSPicker:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
UILabel * feedbackMsg = [[UILabel alloc]initWithFrame:CGRectMake(10, 300, self.view.frame.size.width -20, 30)];
feedbackMsg.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:feedbackMsg];
self.feedbackMsg = feedbackMsg;
}
// -------------------------------------------------------------------------------
// messageComposeViewController:didFinishWithResult:
// Dismisses the message composition interface when users tap Cancel or Send.
// Proceeds to update the feedback message field with the result of the
// operation.
// 当用户点击取消或发送时,关闭消息组合界面。
// 收到更新反馈消息字段的结果操作。
// -------------------------------------------------------------------------------
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result
{
self.feedbackMsg.hidden = NO;
// Notifies users about errors associated with the interface
// 通知用户与界面相关的错误
switch (result)
{
case MessageComposeResultCancelled: //取消
self.feedbackMsg.text = @"Result: SMS sending canceled";
break;
case MessageComposeResultSent: //发送
self.feedbackMsg.text = @"Result: SMS sent";
break;
case MessageComposeResultFailed: //失败
self.feedbackMsg.text = @"Result: SMS sending failed";
break;
default: //默认
self.feedbackMsg.text = @"Result: SMS not sent";
break;
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有