本地调用短信分享。

 #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. sql查询比较两表不同数据与相同数据

    以下举例是查询相同数据,否则则相反 方法一: select * from A as x,B as y where x.a1=y.b1 and x.a2=y.b2 and x.a3=y.b3 方法二: ...

  2. ActionBar使用

    在Android3.0之后,Google对UI导航设计上进行了一系列的改革,其中有一个非常好用的新功能就是引入的ActionBar,他用于取代3.0之前的标题栏,并提供更为丰富的导航效果. 一.添加A ...

  3. 字符集与编码01--charset vs encoding

    声明:此文章转载自 http://my.oschina.net/goldenshaw/blog/304493 许多时候,字符集与编码这两个概念常被混为一谈,但两者是有差别的,作为深入理解的第一步,首先 ...

  4. Unity3D性能优化--- 收集整理的一堆

    http://www.cnblogs.com/willbin/p/3389837.html 官方优化文档--优化图像性能http://docs.unity3d.com/Documentation/Ma ...

  5. C 语言 homework(2)

    <C语言程序设计>实验报告 学 号 160809215 姓 名 韩笑 专业.班 计科16-2班 学 期 2016-2017 第1学期 指导教师 黄俊莲 吴喆 实验地点 C区二层机房 机 器 ...

  6. PyCharm 5 破解注册方法

    方法: 调整时间到2038年. 申请30天试用 退出pycharm 时间调整回来即可. 或者: 注册时选择 License server ,填 http://idea.lanyus.com ,然后点击 ...

  7. 百度地图API 海量点 自定义添加信息

    <!--添加百度地图--> <script type="text/javascript" src="http://api.map.baidu.com/a ...

  8. 初识Flask

    首先在学习flask的前提,我是使用了很久的django和tornado,现在在写总结也是本着工作后方便使用flask 少点东西,对flask的介绍和优点总结 1.安装 pip install fla ...

  9. 解决vi/vim中粘贴会在行首多很多缩进和空格的问题

    解决vi/vim中粘贴会在行首多很多缩进和空格的问题 secureCRT会将你原来的文本原封不动的按照字符串的样式发送给服务器.所以当你的服务器上的vim设置为autoindent的话,在i模式下,那 ...

  10. DIV的摇晃效果---jquery实现

    DIV的摇晃效果---jquery实现 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...