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];
}

 

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。