本地调用短信分享。

 #import "shareViewController.h"

 @interface shareViewController (){
UIAlertView *mfAlertview;//定义一个弹出框
UITextView* txYaoqingma;
} @end @implementation shareViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (IBAction)shareButClick:(id)sender { [self showMessageViewController];
} -(void)showMessageViewController
{
if( [MFMessageComposeViewController canSendText] )//判断是否能发短息
{ MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc]init];
controller.recipients = [NSArray arrayWithObject:@""];//接收人,可以有很多,放入数组
controller.body = txYaoqingma.text;//短信内容,自定义即可
controller.messageComposeDelegate = self;//注意不是delegate [self presentViewController:controller animated:YES completion:nil]; [[[[controller viewControllers] lastObject] navigationItem] setTitle:@"发送短信"];//修改短信界面标题
}
else
{ UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"抱歉" message:@"短信功能不可用!" delegate:self cancelButtonTitle:@"好" otherButtonTitles:nil, nil];
[alert show];
}
} //短信发送成功后的回调
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[controller dismissViewControllerAnimated:YES completion:nil]; switch (result)
{
case MessageComposeResultCancelled:
{
//用户取消发送
}
break;
case MessageComposeResultFailed://发送短信失败
{
mfAlertview=[[UIAlertView alloc]initWithTitle:@"抱歉" message:@"短信发送失败" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil, nil]; [mfAlertview show]; }
break;
case MessageComposeResultSent:
{
mfAlertview=[[UIAlertView alloc]initWithTitle:@"恭喜" message:@"短信发送成功!" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil, nil]; [mfAlertview show]; }
break;
default:
break;
}
}

添加邮件分享

 //邮件

 -(void)showMailPicker {

     Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));

     if (mailClass !=nil) {

         if ([mailClass canSendMail]) {

             [self displayMailComposerSheet];

         }else{

             UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@""message:@"设备不支持邮件功能" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];

             [alert show];

         }

     }else{

     }

 }

 -(void)displayMailComposerSheet

 {

     MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

     picker.mailComposeDelegate =self;

     [picker setSubject:@"文件分享"];

     // Set up recipients

     NSArray *toRecipients = [NSArray arrayWithObject:@"first@qq.com"];

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

     NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@qq.com"];

     [picker setToRecipients:toRecipients];

     [picker setCcRecipients:ccRecipients];

     [picker setBccRecipients:bccRecipients];

     //发送图片附件

     //NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"jpg"];

     //NSData *myData = [NSData dataWithContentsOfFile:path];

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

     //发送txt文本附件

     //NSString *path = [[NSBundle mainBundle] pathForResource:@"MyText" ofType:@"txt"];

     //NSData *myData = [NSData dataWithContentsOfFile:path];

     //[picker addAttachmentData:myData mimeType:@"text/txt" fileName:@"MyText.txt"];

     //发送doc文本附件

     //NSString *path = [[NSBundle mainBundle] pathForResource:@"MyText" ofType:@"doc"];

     //NSData *myData = [NSData dataWithContentsOfFile:path];

     //[picker addAttachmentData:myData mimeType:@"text/doc" fileName:@"MyText.doc"];

     //发送pdf文档附件

     /*

      NSString *path = [[NSBundlemainBundle] pathForResource:@"CodeSigningGuide"ofType:@"pdf"];

      NSData *myData = [NSDatadataWithContentsOfFile:path];

      [pickeraddAttachmentData:myData mimeType:@"file/pdf"fileName:@"rainy.pdf"];

      */

     // Fill out the email body text

     NSString *emailBody =[NSString stringWithFormat:@"我分享了文件给您,地址是%@",@"address"] ;

     [picker setMessageBody:emailBody isHTML:NO];

     [self presentModalViewController:picker animated:YES];

 }

 - (void)mailComposeController:(MFMailComposeViewController*)controller

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

     // Notifies users about errors associated with the interface

     switch (result)

     {

         caseMFMailComposeResultCancelled:

             NSLog(@"Result: Mail sending canceled");

             break;

         caseMFMailComposeResultSaved:

             NSLog(@"Result: Mail saved");

             break;

         caseMFMailComposeResultSent:

             NSLog(@"Result: Mail sent");

             break;

         caseMFMailComposeResultFailed:

             NSLog(@"Result: Mail sending failed");

             break;

         default:

             NSLog(@"Result: Mail not sent");

             break;

     }

     [self dismissModalViewControllerAnimated:YES];

 }

iOS 短信分享 邮件分享的更多相关文章

  1. iOS调用系统发送短信和邮件分享

    //发送邮件 -(void)sendMail:(NSString*)subject content:(NSString*)content{ MFMailComposeViewController*co ...

  2. IOS中调用系统的电话、短信、邮件、浏览功能

    iOS开发系列--通讯录.蓝牙.内购.GameCenter.iCloud.Passbook系统服务开发汇总 2015-01-13 09:16 by KenshinCui, 26990 阅读, 35 评 ...

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

    一,设置亮度 [[UIScreen mainScreen] setBrightness:0.5];//0.0~1.0 二,设置声音 1,添加 MediaPlayer.framework 框架 2,在需 ...

  4. iOS学习笔记28-系统服务(一)短信和邮件

    一.系统应用 在开发某些应用时,我们可能希望能够调用iOS系统内置的电话.短信.邮件.浏览器应用,或者直接调用安装的第三方应用,这个要怎么实现呢? 这里统一使用UIApplication的一个对象方法 ...

  5. ios开发——实用技术篇Swift篇&地址薄、短信、邮件

    //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnimated(tru ...

  6. 整理:iOS 短信与电话事件的获取

    整理:iOS 短信与电话事件的获取   background information: Core Telephony iOS 4.0 的官方 API 裡頭,多了一個叫做 Core Telephony  ...

  7. react-native-communications 电话、短信、邮件、浏览器

    第一种方法:Linking:调用系统的电话.短信.邮件.浏览器等功能 Linking.canOpenURL(this.props.url).then(supported => { if (!su ...

  8. HTML5的头部、拨号、短信、邮件(转)

    HTML5[语法要点] 一.头部设置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 <!--页面窗口自动调整到设备 ...

  9. MVC使用ASP.NET Identity 2.0实现用户身份安全相关功能,比如通过短信或邮件发送安全码,账户锁定等

    本文体验在MVC中使用ASP.NET Identity 2.0,体验与用户身份安全有关的功能: →install-package Microsoft.AspNet.Identity.Samples - ...

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

    结果: 1.不提示发短信卡住,点击没有反映,我猜想,可能是因为我用的是小米手机吧. 2.接收短信报错,我猜想可能是我改了里面的方法吧(哪位大神了解,求指教). 3.project -->opti ...

随机推荐

  1. C 文件读写 容易疏忽的一个问题

    今天需要解决一个问题,将影像瓦片(一堆jpg文件)分别进行读取,并将所有数据以文件流的方式存入一个.db的文件中, 同时将每个jpg数据在db文件中的位置保存下来,作为index存在.idx文件中. ...

  2. updatepanel用法之triggers(局部刷新,全部刷新)使用示例

    asyncpostbacktrigger(异步回调触发器):局部刷新,只刷新updatepanel内部的内容postbacktrigger(普通回调触发器):全部刷新 <asp:ScriptMa ...

  3. Entity Framework 之Database first(数据库优先)&Model First(模型优先)

    一.什么是Entity Framework 1.1 实体框架(EF)是一个对象关系映射器,使.NET开发人员使用特定于域的对象与关系数据.它消除了需要开发人员通常需要编写的大部分数据访问代码.简化了原 ...

  4. The report for triangle problem

    本次实验主要使用eclipse 编写三角形判定的代码,并用junit进行测试. 1.安装junit和hamcrest 下载junit-4.12.jar和hamcrest-all-1.3.jar 并且拖 ...

  5. BZOJ2049——[Sdoi2008]Cave 洞穴勘测

    1.题目大意:就是一个动态维护森林联通性的题 2.分析:lct模板题 #include <stack> #include <cstdio> #include <cstdl ...

  6. android之inflater用法

    在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById().不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例 ...

  7. nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoSupport': ...

  8. zabbix3.0报错记录

    一.问题描述 在zabbix_server添加变量时,出现了以下的报错,

  9. [20160707]Java中如何关闭Frame窗口

    用户类继承自WindowAdapter,而窗口对象Frame作为用户类的数据成员. 1 import java.awt.*; import java.awt.event.*; public class ...

  10. jQuery数组($.each,$.grep,$.map,$.merge,$.inArray,$.unique,$.makeArray)处理函数详解

    1. $.each(array, [callback]) 遍历[常用] 解释: 不同于例遍jQuery对象的$().each()方法,此方法可用于例遍任何对象.回调函数拥有两个参数:第一个为对象的成员 ...