//调用自带mail [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@hzlzh.com"]]; //调用电话 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]]; //调用sms [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]]; //调用打开网址 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu.com"]];
调用phone可以传递号码,调用SMS 只能设定号码,不能初始化SMS内容。
发短信邮件需要的框架
导入头文件#import <MessageUI/MessageUI.h>
协议:<MFMailComposeViewControllerDelegate,MFMessageComposeViewControllerDelegate>
//点击按钮后,触发这个方法 -(void)sendEMail { MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init]; mailPicker.mailComposeDelegate = self; //设置主题 [mailPicker setSubject: @"eMail主题"]; // 添加发送者 NSArray *toRecipients = [NSArray arrayWithObject: @"first@example.com"]; [mailPicker setToRecipients: toRecipients]; // 添加图片 UIImage *addPic = [UIImage imageNamed: @"ios.jpg"]; NSData *imageData = UIImagePNGRepresentation(addPic); // png // NSData *imageData = UIImageJPEGRepresentation(addPic, 1); // jpeg [mailPicker addAttachmentData: imageData mimeType: @"" fileName: @"ios.jpg"]; NSString *emailBody = @"eMail 正文"; [mailPicker setMessageBody:emailBody isHTML:YES]; [self presentViewController:mailPicker animated:YES completion:nil]; } - (void)sendSMS{ MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init]; if([MFMessageComposeViewController canSendText]) { controller.body = @"12"; controller.recipients = @[@"1",@"2"]; controller.messageComposeDelegate = self; [self presentViewController:controller animated:YES completion:nil]; } } #pragma mark - <MFMessageComposeViewControllerDelegate> // 处理发送完的响应结果 - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; if (result == MessageComposeResultCancelled){ NSLog(@"Message cancelled"); } else if (result == MessageComposeResultSent){ NSLog(@"Message sent"); } else{ NSLog(@"Message failed"); } } #pragma mark - <MFMailComposeViewControllerDelegate> - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { NSString *msg; switch (result) { case MFMailComposeResultCancelled: msg = @"邮件发送取消"; break; case MFMailComposeResultSaved: msg = @"邮件保存成功"; break; case MFMailComposeResultSent: msg = @"邮件发送成功"; break; case MFMailComposeResultFailed: msg = @"邮件发送失败"; break; default: break; } [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; }