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


        //调用自带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];
    }
     
  • 相关阅读:
    js-实现点击按钮直接打印
    XMLHTTPREQUEST–获取上传文件的进度
    The prop 'history' is marked as required in 'Router', but its value is 'undefined'.in Router
    javascript之闭包,递归,深拷贝
    node之get与post
    css公共样式
    php之创建jsonp接口调数据
    javascript之创建对象的方式
    angular之两种路由
    php之上传图片及传数据到mysql
  • 原文地址:https://www.cnblogs.com/hxwj/p/4550572.html
Copyright © 2020-2023  润新知