iOS 短信分享 邮件分享
本地调用短信分享。
#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 短信分享 邮件分享的更多相关文章
- iOS调用系统发送短信和邮件分享
//发送邮件 -(void)sendMail:(NSString*)subject content:(NSString*)content{ MFMailComposeViewController*co ...
- IOS中调用系统的电话、短信、邮件、浏览功能
iOS开发系列--通讯录.蓝牙.内购.GameCenter.iCloud.Passbook系统服务开发汇总 2015-01-13 09:16 by KenshinCui, 26990 阅读, 35 评 ...
- ios 设置亮度、声音;调用发短信、邮件、打电话
一,设置亮度 [[UIScreen mainScreen] setBrightness:0.5];//0.0~1.0 二,设置声音 1,添加 MediaPlayer.framework 框架 2,在需 ...
- iOS学习笔记28-系统服务(一)短信和邮件
一.系统应用 在开发某些应用时,我们可能希望能够调用iOS系统内置的电话.短信.邮件.浏览器应用,或者直接调用安装的第三方应用,这个要怎么实现呢? 这里统一使用UIApplication的一个对象方法 ...
- ios开发——实用技术篇Swift篇&地址薄、短信、邮件
//返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnimated(tru ...
- 整理:iOS 短信与电话事件的获取
整理:iOS 短信与电话事件的获取 background information: Core Telephony iOS 4.0 的官方 API 裡頭,多了一個叫做 Core Telephony ...
- react-native-communications 电话、短信、邮件、浏览器
第一种方法:Linking:调用系统的电话.短信.邮件.浏览器等功能 Linking.canOpenURL(this.props.url).then(supported => { if (!su ...
- 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 <!--页面窗口自动调整到设备 ...
- MVC使用ASP.NET Identity 2.0实现用户身份安全相关功能,比如通过短信或邮件发送安全码,账户锁定等
本文体验在MVC中使用ASP.NET Identity 2.0,体验与用户身份安全有关的功能: →install-package Microsoft.AspNet.Identity.Samples - ...
- Android实例-打电话、发短信和邮件,取得手机IMEI号(XE8+小米2)
结果: 1.不提示发短信卡住,点击没有反映,我猜想,可能是因为我用的是小米手机吧. 2.接收短信报错,我猜想可能是我改了里面的方法吧(哪位大神了解,求指教). 3.project -->opti ...
随机推荐
- window使用qt遇到的坑
1.window上的qt对图片的检测与识别不够完善.往往改了一个ui的背景图片,运行出来显示的却是旧的背景图片. 原因: 由于之前是项目与项目之间整合在一起,然后把ui_*_ui.h的临时文件也放在 ...
- servlet过滤器实现维护项目
最近公司需要系统维护,提出要建一个维护系统,要求: 1.访问公司域名跳到系统首页 2.点击首页的任意按钮给出维护提示信息 3.用户访问之前收藏的任意系统链接跳转到首页 下面介绍下用过滤器实现上述需求 ...
- Javascript高级程序设计——执行环境与作用域
Javascript中执行环境是定义了变量或函数有权访问的其他数据,决定了各自的行为,每个执行的环境都有一个与之关联的变量对象,环境中定义的所以变量和函数都保存在这个对象中. 全局执行环境是最外围的一 ...
- WordPress文章浏览历史插件
选自:http://www.ludou.org/wordpress-recently-viewed.html 最近有很多网友问我,露兜博客右边栏底部的 您刚刚看过 栏目是怎么实现.其实我也是参考的这篇 ...
- android快速开发框架
网络: socket: mina http: http://loopj.com/android-async-http/ UI: http://jakewharton.github.io/butterk ...
- __get().__set.__isset,__unset魔术方法
一般来说,总是把类的属性定义为 private .这更符合现实的逻辑. 但是对属性的读取和赋值操作非常频繁的,因此在PHP中,预定义了两魔术方法 "__get()"用来获取私有成员属性值的,只有一个参 ...
- 36 网络相关函数(四)——live555源码阅读(四)网络
36 网络相关函数(四)——live555源码阅读(四)网络 36 网络相关函数(四)——live555源码阅读(四)网络 简介 7)createSocket创建socket方法 8)closeSoc ...
- 为什么要继承ActionSupport?
struts2中的action可以继承ActionSupport,也可以不继承ActionSupport.不继承ActionSupport的情况只需要有一个方法,返回String,即可,记住,在继承A ...
- jquery 打印宽高
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- OracleBulkCopy
Oracle也有BulkCopy了,需要安装oracle 11g,并引用客户端下面的Oracle.DataAccess.dll 用法和SQLBulkCopy差不多 connStr 是 ORACLE 的 ...