iOS学习笔记8-iOS 实现发送邮件和短信

导入framework

导入MessageUI.framework

发送邮件

首先需要在.h文件中实现下面的操作:
  1. #import <MessageUI/MFMailComposeViewController.h>  
然后实现下面的代理 :MFMailComposeViewControllerDelegate

  1. - (void)businessContactWithMail  
  2. {  
  3.     Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));  
  4.     if (mailClass != nil)  
  5.     {  
  6.         // We must always check whether the current device is configured for sending emails  
  7.         if ([mailClass canSendMail])  
  8.         {  
  9.             MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];  
  10.             picker.mailComposeDelegate = self;  
  11.             [picker setToRecipients:[NSArray arrayWithObject:@""]];  
  12.             [picker setSubject:[NSString stringWithFormat:@""]];  
  13.               
  14.             UIDevice *device = [UIDevice currentDevice];  
  15.               
  16.             NSString *content=[NSString stringWithFormat:@""];  
  17.             [picker setMessageBody:content isHTML:NO];  
  18.             [self presentViewController:picker animated:YES completion:^{  
  19.                   
  20.             }];  
  21.         }  
  22.         else  
  23.         {  
  24.             [NDUI showAlertWithInfo:@"您的设备尚未配置邮件账号" title:@"提示"];  
  25.         }  
  26.     } else {  
  27.         [NDUI showAlertWithInfo:@"您的设备不支持邮件功能" title:@"提示"];  
  28.     }  
  29. }  
  30. #pragma mark - Mail and SMS delegate  
  31. // Dismisses the email composition interface when users tap Cancel or Send.  
  32. // Proceeds to update the message field with the result of the operation.  
  33. - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error  
  34. {  
  35.     [self dismissViewControllerAnimated:YES completion:nil];  
  36. }  


短信发送


首先需要在.h文件中实现下面的操作:
  1. #import <MessageUI/MFMailComposeViewController.h>  
然后实现下面的代理 :MFMessageComposeViewControllerDelegate
  1. - (void)shareWithSMS  
  2. {  
  3.     Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));  
  4.     BOOL smsEnabled=NO;  
  5.     if (messageClass != nil) {            
  6.         // Check whether the current device is configured for sending SMS messages  
  7.         if ([messageClass canSendText]) {  
  8.             MFMessageComposeViewController *smsClident = [[MFMessageComposeViewController alloc] init];  
  9.             smsClident.messageComposeDelegate = self;  
  10.               
  11.             NSString *messageBody = [NSString stringWithFormat:@""];  
  12.               
  13.             [smsClident setBody:messageBody];  
  14.             [self presentModalViewController:smsClident animated:YES];  
  15.         }  
  16.         else {    
  17.             [NDUI showAlertWithInfo:@"您的设备不支持此短信功能" title:@"提示"];  
  18.         }  
  19.     }  
  20.     else {  
  21.           
  22.         [NDUI showAlertWithInfo:@"您的设备不支持短信功能" title:@"提示"];  
  23.     }  
  24.     if(!smsEnabled){  
  25.         return;  
  26.     }  
  27.       
  28.       
  29. }  
  30. - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result  
  31. {  
  32.     [self dismissModalViewControllerAnimated:YES];  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值