iOS打电话,发短信,发邮件,打开网址

    //调用自带mail
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];

    //调用电话
    [[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: @"[email protected]"];

    [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];
}
时间: 2024-08-03 19:22:23

iOS打电话,发短信,发邮件,打开网址的相关文章

ios 设置亮度、声音;调用发短信、邮件、打电话

一,设置亮度 [[UIScreen mainScreen] setBrightness:0.5];//0.0~1.0 二,设置声音 1,添加 MediaPlayer.framework 框架 2,在需要的文件中导入头文件,#import <MediaPlayer/MediaPlayer.h> 3,[[MPMusicPlayerController applicationMusicPlayer] setVolume: 0.5];//0.0~1.0 三,调用发短信.邮件.打电话 1.调用 自带ma

Android实例-打电话、发短信和邮件,取得手机IMEI号(XE8+小米2)

结语: 1.不提示发短信卡住,点击没有反映,我猜想,可能是因为我用的是小米手机吧. 2.接收短信报错,我猜想可能是我改了里面的方法吧(哪位大神了解,求指教). 3.project -->options…--> users permitions. 3.1 Send SMS 3.2 Read Phone State权限:将其变成 true即可. 如果 read phone state为 false,程序将启动不了,一直黑屏(我没试,原作者是这么说的,你如果没事可以试一试,试过记得给我说一声哦).

如何实现打电话,发短信,发邮件,打开网页功能

我们在做APP的时候,难免会遇到需要调用短信,电话等程序的时候.如美团. 当然,这些都只是一些简单的方法就可以实现,但是时间久了也会淡忘,所以想写这边博客.一是为了再捡起来复习一下,另一个相当于留个备份,以后忘了,自己也可以捡起来看看. 首先,说说如何调用浏览器打开网页. 当然这个就很简单了,只需要短短两句话就可以实现 NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"]; // [[UIApplication share

iOS打电话发短信发邮件总结

今天把APP里常用小功能 例如发短信.发邮件.打电话. 全部拿出来简单说说它们的实现思路. 1.发短信 实现打电话的功能,主要二种方法,下面我就分别说说它们的优缺点. 1.1.发短信(1)——URL // 直接拨号,拨号完成后会停留在通话记录中 1.方法: NSURL *url = [NSURL URLWithString:@"sms://10010"]; [[UIApplication sharedApplication] openURL:url]; 2.优点: –简单 3.缺点:

【学习ios之路:UI系列】实现打电话,发短信,发邮件功能

①发短信 1.创建Button ,添加button的响应事件 UIButton *callButton = [UIButton buttonWithType:UIButtonTypeCustom]; callButton.frame = CGRectMake(80, 150, 80, 80); callButton.backgroundColor = [UIColor cyanColor]; [callButton setTitle:@"短信" forState:UIControlSt

调用系统的打电话,发短信,邮件,蓝牙

在开发某些应用时可能希望能够调用iOS系统内置的电话.短信.邮件.浏览器应用,此时你可以直接使用UIApplication的OpenURL:方法指定特定的协议来打开不同的系统应用.常用的协议如下: 打电话:tel:或者tel://.telprompt:或telprompt://(拨打电话前有提示) 发短信:sms:或者sms:// 发送邮件:mailto:或者mailto:// 启动浏览器:http:或者http:// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

打电话,发短信,发邮件,app跳转

1.打电话 - (IBAction)callPhone1:(id)sender { NSURL *url = [NSURL URLWithString:@"tel://18500441739"]; [[UIApplication sharedApplication] openURL:url]; } - (IBAction)callPhone2:(id)sender { NSURL *url = [NSURL URLWithString:@"telprompt://185004

APP拨打电话&amp;发短信&amp;发邮件

在移动开发中我们会经常需要调用手机的拨打电话功能.发短信功能和发邮件功能,以下是我总结的方法: //1.打电话 //方法1 最常用方法 NSURL *telUrl = [NSURL URLWithString:"tel://13161906451"]; UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero]; [webView loadRequest:[NSURLRequest requestWithURL:t

iOS 电话/短信/邮件/UIApplication

1,打电话的三种方式:1?? • 最简单最直接的?方式:直接跳到拨号界?面 NSURL *url = [NSURL URLWithString:@"tel://10010"]; [[UIApplication sharedApplication] openURL:url]; • 缺点电话打完后,不会?自动回到原应?用,直接停留在通话记录界?面 2?? • 拨号之前会弹框询问?用户是否拨号,拨完后能?自动回到原应?用NSURL *url = [NSURL URLWithString:@&

iOS开发——发短信,邮件

在IOS开发中,有时候我们会需要用到邮件发送的功能.比如,接收用户反馈和程序崩溃通知等等,这个功能是很常用的.在苹果系统中,如果彼此的手机都是iOS设备,并且开通了iMessage功能,那么彼此之间的短信是走网络通道,而不走运营商的通道,短信也顺便写写喽. 还是老规矩,直接上代码. // //  ViewController.m //  Demo-testEmail // //  Created by yyt on 16/5/16. //  Copyright © 2016年 yyt. All