温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

iOS如何实现打电话、发短信、发邮件

发布时间:2021-07-22 09:33:37 来源:亿速云 阅读:114 作者:小新 栏目:移动开发

这篇文章将为大家详细讲解有关iOS如何实现打电话、发短信、发邮件,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

具体内容如下

1.发短信

头文件

#import <MessageUI/MessageUI.h>

头部代理

@interface ViewController ()<MFMessageComposeViewControllerDelegate>

发送信息

- (void)senderMessage{
  if([MFMessageComposeViewController canSendText]) {
    ///短信实例化
    MFMessageComposeViewController * messageVc = [[MFMessageComposeViewController alloc] init];
    ///目标号码,可以多个
    messageVc.recipients = @[@"18888888888",@"15555555555"];
    messageVc.navigationBar.tintColor = [UIColor redColor];
    messageVc.body = @"发送的内容-发送的内容-发送的内容";
    messageVc.messageComposeDelegate = self;
    [self presentViewController:messageVc animated:YES completion:nil];
    [[[[messageVc viewControllers] lastObject] navigationItem] setTitle:@"title"];
  }
  else {
    NSLog(@"当前设备不支持短信功能");
  }
  
}

代理方法实现

-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
  ///dismiss MFMessageComposeViewController
  [controller dismissViewControllerAnimated:YES completion:nil];
  if (result == MessageComposeResultSent) {
    NSLog(@"信息发送成功!");
  }
  else if (result == MessageComposeResultFailed){
    NSLog(@"信息发送失败!");
  }
  else if (result == MessageComposeResultCancelled){
    NSLog(@"点击了取消");
  }
  else{
    
  }
}

2.拨打电话

- (void)dialPhone{
  ///该方法直接拨打,不会弹出呼叫(取消)
  [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel://18888888888"]];
  
  ///该方法会弹出是否取消呼叫
  UIWebView*callWebview =[[UIWebView alloc] init];
  NSURL *telURL =[NSURL URLWithString:@"tel:18888888888"];
  [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
  [self.view addSubview:callWebview];
}

3.发送邮件

- (void)senderEmail{
  NSString *urlStr =@"mailto:xxxxxxxx@xxxx.com?subject=邮件主题(此参数可不传)&body=邮件内容(此参数可不传)";
  NSURL *url = [NSURL URLWithString:urlStr] ;
  [[UIApplication sharedApplication] openURL:url];
}

4.发送QQ消息

- (void)senderQQ{
  ///111111111111为QQ号码
  NSString *url = @"mqq://im/chat?chat_type=wpa&uin=111111111111&version=1&src_type=web";
  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}

关于“iOS如何实现打电话、发短信、发邮件”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ios
AI