拨打电话
- 遵守协议:UIAlertViewDelegate
- 拨打电话
UIAlertView *alt=[[UIAlertView alloc] initWithTitle:nil message:@“18211453217” delegate:self cancelButtonTitle:@"呼叫" otherButtonTitles:@"取消", nil];
[alt show];
//拨打电话UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
NSString *str = [NSString stringWithFormat:@"tel://%@",alertView.message];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}else{
}
}
发送短信
- 导入头文件 #import <MessageUI/MessageUI.h>
- 遵守协议:UIAlertViewDelegate,MFMessageComposeViewControllerDelegate
- 发送短信
UIAlertView *alt=[[UIAlertView alloc] initWithTitle: initWithTitle:nil message:@“18287671298” delegate:self cancelButtonTitle:@“发送短信” otherButtonTitles:@"取消", nil];
[alt show];
- 实现代理方法UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
//发短信
[self showMessageView:@[alertView.message,@"18010155927"] body:@""];
}else{
}
}
- 实现代理方法MFMessageComposeViewControllerDelegate
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissViewControllerAnimated:YES completion:nil];
switch (result) {
case MessageComposeResultSent:
//信息传送成功
break;
case MessageComposeResultFailed:
//信息传送失败
break;
case MessageComposeResultCancelled:
//信息被用户取消传送
break;
default:
break;
}
}
-(void)showMessageView:(NSArray *)phones body:(NSString *)body
{
if( [MFMessageComposeViewController canSendText] )
{
MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
controller.recipients = phones;
controller.navigationBar.tintColor = [UIColor redColor];
controller.body = body;
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"该设备不支持短信功能" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
}
}
发送邮件
- 遵守协议:UIAlertViewDelegate
- 发送邮件
UIAlertView *alt=[[UIAlertView alloc] initWithTitle:@"发送邮件" message:@"123@163.com” delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
[alt show];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
[self launchMailApp:alertView.message];
}else{
}
}
-
pragma mark - 使用系统邮件客户端发送邮件
-(void)launchMailApp:(NSString *)emailStr{
NSMutableString *mailUrl = [[NSMutableString alloc]init];
//添加收件人
NSArray *toRecipients = [NSArray arrayWithObject: emailStr];
[mailUrl appendFormat:@"mailto:%@", [toRecipients componentsJoinedByString:@","]];
//添加抄送
// NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
// [mailUrl appendFormat:@"?cc=%@", [ccRecipients componentsJoinedByString:@","]];
//添加密送
// NSArray *bccRecipients = [NSArray arrayWithObjects:@"fourth@example.com", nil];
// [mailUrl appendFormat:@"&bcc=%@", [bccRecipients componentsJoinedByString:@","]];
//添加主题
[mailUrl appendString:@"&subject=my email"];
//添加邮件内容
[mailUrl appendString:@"&body=emailbody!"];
NSString* email = [mailUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:email]];
}
网友评论
发送短信的哈,文章也更新了,谢谢纠正🙏