iOS调用电话、短信、邮件(Objective-C)

2018.4.3
简单调用 电话、短信、邮件 代码示例,

打个电话
NSString *openUrl = [NSString stringWithFormat:@"tel://%@", mobile];
if (@available(iOS 10.0, *)) {
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl] options:@{} completionHandler:nil];
} else {
     // Fallback on earlier versions
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl]];
}
发条短信
1.引入头文件 
#import 

2.遵守协议
MFMessageComposeViewControllerDelegate

3.代码调用
if (![MFMessageComposeViewController canSendText]) {
      NSLog(@"当前设备不支持短信分享!");
      return;
}

MFMessageComposeViewController *msgVC = [[MFMessageComposeViewController alloc] init];
msgVC.recipients = @[@"10086", @"10000"];/* 收信人列表 */
msgVC.body = @"这是短信正文内容";
msgVC.messageComposeDelegate = self;
[self.navigationController pushViewController:msgVC animated:YES];
发封邮件
1.引入头文件 
#import 

2.遵守协议
MFMailComposeViewControllerDelegate

3.代码调用
if (![MFMailComposeViewController canSendMail]) {
      NSLog(@"当前设备不支持邮件分享!");
      return;
}

MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
[mailVC setToRecipients:@[@"[email protected]", @"[email protected]"]];/* 收件人列表 */
[mailVC setCcRecipients:@[@"[email protected]", @"[email protected]"]];/* 抄送人列表 */
[mailVC setBccRecipients:@[@"[email protected]", @"[email protected]"]];/* 密送人列表 */
[mailVC setSubject:@"这是主题"];
[mailVC setMessageBody:@"这是邮件正文内容" isHTML:NO];
/*添加附件,mimeType不能为nil */
[mailVC addAttachmentData:UIImageJPEGRepresentation([UIImage new], 0.9) mimeType:@"image/jpg" fileName:@"附件是图片.jpeg"];
mailVC.mailComposeDelegate = self;
[self.navigationController pushViewController:mailVC animated:YES];

你可能感兴趣的:(iOS调用电话、短信、邮件(Objective-C))