iOS调用电话、短信、邮件、QQ

一、打电话的两种方式

①通过Application
      
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:@"tel://10086"]];
②通过WebView
NSURL *url = [NSURL URLWithString:@"tel://10086"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];

二、发短信的两种方式

①通过Application
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:@"sms://10086,13613633445"]];
②通过发短信视图控制器
MFMessageComposeViewController *vc = [[MFMessageComposeViewController alloc] init];
设置发送对象
vc.recipients=@[@"13613800129",@"10086"];
设置发送短信内容
vc.body=@"你好,恭喜您获得了一等奖";
设置代理  
vc.messageComposeDelegate=self;
[selfpresentViewController:vcanimated:YEScompletion:nil];

协议方法
- (void)messageComposeViewController:(MFMessageComposeViewController*)controller didFinishWithResult:(MessageComposeResult)result{
    switch (result) {
        case MessageComposeResultCancelled:                              取消发送
            [self dismissViewControllerAnimated:YES completion:nil];
            break;
        case MessageComposeResultSent:                                     发送成功
            [self dismissViewControllerAnimated:YES completion:nil];
            break;
        case MessageComposeResultFailed:                                   发送失败
           break; 
        default:
            break;
    }
}

三、发邮件

①通过Application
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:@"mailto://452516188@163.com"]];
②通过发邮件视图控制器
MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
//设置代理
vc.mailComposeDelegate=self;
//设置邮件标题
[vc setSubject:@"生日快乐"];
//设置邮件发送对象
[vc setToRecipients:@[@"452516188@163.com",@"123123@qq.com"]];
//设置抄送对象
[vc setCcRecipients:@[@"asd@163.com"]];
//设置邮件正文内容
[vc setMessageBody:@"祝你生日快乐,长命百岁"isHTML:NO];
[self presentViewController:vc animated:YES completion:nil];
协议方法
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(nullableNSError*)error{
    switch (result) {
        case MFMailComposeResultCancelled:                                取消发送
            [self dismissViewControllerAnimated:YES completion:nil];
            break;
        case MFMailComposeResultSaved:                                     取消并保存
            [self dismissViewControllerAnimated:YES completion:nil];    
           break;
        case MFMailComposeResultSent:                                        发送成功
            [self dismissViewControllerAnimated:YES completion:nil];    
           break;
        case MFMailComposeResultFailed:                                     发送失败
           break;
       default:
            break;
    }
}

四、打开QQ

NSString *qq = 
[NSString stringWithFormat:
@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",@"QQ号"];
NSURL *url = [NSURL URLWithString:qq];
[[UIApplication sharedApplication] openURL:url];

需在info.plist文件中加入下面行
<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>mqq://</string>
			</array>
		</dict>
	</array>







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值