博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS 打电话 发短信(转载)
阅读量:6668 次
发布时间:2019-06-25

本文共 5970 字,大约阅读时间需要 19 分钟。

官方代码

发短息和邮件添加MessageUI.framework 库

 

发送信息

- (IBAction)showSMSPicker:(id)sender

{

    // You must check that the current device can send SMS messages before you

    // attempt to create an instance of MFMessageComposeViewController.  If the

    // device can not send SMS messages,

    // [[MFMessageComposeViewController alloc] init] will return nil.  Your app

    // will crash when it calls -presentViewController:animated:completion: with

    // a nil view controller.

    if ([MFMessageComposeViewControllercanSendText])

    // The device can send email.

    {

        [selfdisplaySMSComposerSheet];

    }

    else

    // The device can not send email.

    {

        self.feedbackMsg.hidden =NO;

      self.feedbackMsg.text = @"Device not configured to send SMS.";

    }

 

 

- (void)displaySMSComposerSheet 

{

 

   MFMessageComposeViewController *picker = [[MFMessageComposeViewControllerallocinit];

    picker.messageComposeDelegate =self;

    picker.navigationBar.tintColor = [UIColorblackColor];

    picker.recipients = [NSArrayarrayWithObject:@"186888888"];

    picker.body =@"Hello from California!";

    

    [selfpresentViewController:picker animated:YEScompletion:NULL];

}

 

// -------------------------------------------------------------------------------

// messageComposeViewController:didFinishWithResult:

//  Dismisses the message composition interface when users tap Cancel or Send.

//  Proceeds to update the feedback message field with the result of the

//  operation.

// -------------------------------------------------------------------------------

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller 

  didFinishWithResult:(MessageComposeResult)result

{

self.feedbackMsg.hidden =NO;

// Notifies users about errors associated with the interface

switch (result)

{

caseMessageComposeResultCancelled:

self.feedbackMsg.text = @"Result: SMS sending canceled";

break;

caseMessageComposeResultSent:

self.feedbackMsg.text = @"Result: SMS sent";

break;

caseMessageComposeResultFailed:

self.feedbackMsg.text = @"Result: SMS sending failed";

break;

default:

self.feedbackMsg.text = @"Result: SMS not sent";

break;

}

    

[selfdismissViewControllerAnimated:YEScompletion:NULL];

}

 

发送邮件

 

- (IBAction)showMailPicker:(id)sender

{

    // You must check that the current device can send email messages before you

    // attempt to create an instance of MFMailComposeViewController.  If the

    // device can not send email messages,

    // [[MFMailComposeViewController alloc] init] will return nil.  Your app

    // will crash when it calls -presentViewController:animated:completion: with

    // a nil view controller.

    if ([MFMailComposeViewControllercanSendMail])

    // The device can send email.

    {

        [selfdisplayMailComposerSheet];

    }

    else

    // The device can not send email.

    {

        self.feedbackMsg.hidden =NO;

self.feedbackMsg.text =@"Device not configured to send mail.";

    }

}

 

#pragma mark - Compose Mail/SMS

 

// -------------------------------------------------------------------------------

// displayMailComposerSheet

//  Displays an email composition interface inside the application.

//  Populates all the Mail fields.

// -------------------------------------------------------------------------------

- (void)displayMailComposerSheet 

{

 

MFMailComposeViewController *picker = [[MFMailComposeViewControllerallocinit];

picker.mailComposeDelegate =self;

 

[picker setSubject:@"Hello from California!"];

 

// Set up recipients

 

NSArray *toRecipients = [NSArrayarrayWithObject:@"first@example.com"]; 

NSArray *ccRecipients = [NSArrayarrayWithObjects:@"second@example.com",@"third@example.com"nil]; 

NSArray *bccRecipients = [NSArrayarrayWithObject:@"fourth@example.com"]; 

 

[picker setToRecipients:toRecipients];

[picker setCcRecipients:ccRecipients];

[picker setBccRecipients:bccRecipients];

 

// Attach an image to the email

 

NSString *path = [[NSBundlemainBundlepathForResource:@"rainy"ofType:@"jpg"];

NSData *myData = [NSDatadataWithContentsOfFile:path];

[picker addAttachmentData:myData mimeType:@"image/jpeg"fileName:@"rainy"];

 

 

// Fill out the email body text

 

 

NSString *emailBody =@"It is raining in sunny California!";

[picker setMessageBody:emailBody isHTML:NO];

 

[selfpresentViewController:picker animated:YEScompletion:NULL];

 

 

}

 

 

#pragma mark - Delegate Methods

 

// -------------------------------------------------------------------------------

// mailComposeController:didFinishWithResult:

//  Dismisses the email composition interface when users tap Cancel or Send.

//  Proceeds to update the message field with the result of the operation.

// -------------------------------------------------------------------------------

- (void)mailComposeController:(MFMailComposeViewController*)controller 

didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error

{

self.feedbackMsg.hidden =NO;

// Notifies users about errors associated with the interface

switch (result)

{

caseMFMailComposeResultCancelled:

self.feedbackMsg.text = @"Result: Mail sending canceled";

break;

caseMFMailComposeResultSaved:

self.feedbackMsg.text = @"Result: Mail saved";

break;

caseMFMailComposeResultSent:

self.feedbackMsg.text = @"Result: Mail sent";

break;

caseMFMailComposeResultFailed:

self.feedbackMsg.text = @"Result: Mail sending failed";

break;

default:

self.feedbackMsg.text = @"Result: Mail not sent";

break;

}

    

[selfdismissViewControllerAnimated:YEScompletion:NULL];

}

 

打电话 我只写了一种简单的方式 还有其他的

添加  AddressBookUI.framework 库

 

#import <AddressBook/AddressBook.h>

#import <AddressBook/ABMultiValue.h>

#import <AddressBook/ABRecord.h>

 

 

 

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

{

    NSString *key = [keyArrayobjectAtIndex:indexPath.row];

    NSArray *array = [tableDataDictionaryobjectForKey:key];

    

    NSString *phoneNum = [arrayobjectAtIndex:1];//电话号码

    

    NSURL *phoneURL = [NSURLURLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];

    

    if ( !_phoneCallWebView ) {

        

        _phoneCallWebView = [[UIWebViewallocinitWithFrame:CGRectZero];

        

    }

    

    [_phoneCallWebViewloadRequest:[NSURLRequest requestWithURL:phoneURL]];

   

}

 

转载于:https://www.cnblogs.com/alihaiseyao/p/3709530.html

你可能感兴趣的文章
Linux中zip压缩和unzip解压缩命令详解
查看>>
DevExpress学习03——label控件的背景色问题
查看>>
微信全球MBA创新大赛麻省理工学院的WeChat Care团队夺魁
查看>>
properties 中文乱码问题的解决
查看>>
2015第15周一
查看>>
腾讯一面总结(转)
查看>>
Loadrunner参数化如何在记事本中将参数值显示超过100个参数值
查看>>
更改默认alert框体
查看>>
[Shell学习笔记] 命令行下的高级网络工具cURL命令
查看>>
同步、异步、阻塞和非阻塞区别
查看>>
get改造成post请求
查看>>
linux文件分割(将大的日志文件分割成小的)
查看>>
使用LNMP常见问题解答
查看>>
python网络爬虫进入(一)——简单的博客爬行动物
查看>>
好玩的SQL
查看>>
TFS Express backup and restore
查看>>
fastjson初始化对性能的影响(转)
查看>>
确定只出现曾有两位数字数组
查看>>
Facebook 调试工具Stetho配置入门
查看>>
win7安装ruby on rails开发环境
查看>>