iOS 通过邮件分享app生成的视频
2016-09-23 09:05
513 查看
最近在研究app内的视频 分享出去,最好能分享到其他第三方应用如twitter,Facebook,微信,微博等,网上全是一些什么SDK,都是只能分享图片,url等,并不是我想要的,最后实在没办法了,只能用分享邮件的方式,把视频分享出去。好了下面开始分享代码!
.h里面
.m文件里面实现为
这样就可以发送视频到邮件了,但是还需要一个代理,发送完退出present的邮件窗口;
邮件分享是无法在模拟器上运行的,必须要真机,上面的代码,地址取的是外面拖进project的名字自动取得的,但是在app里面,我们如何取得app自己生成的地址呢?
这就需要 enumeratorAtPath 来遍历app中的视频
详细可见这篇博客
http://blog.csdn.net/p2game/article/details/17766427
由于本人技术有限,如有写的不科学的地方,还请指出来,大家一起交流!
如果大家有分享视频的好方法,也希望与博主分享一下,共同进步!
.h里面
#import <UIKit/UIKit.h> #import <MessageUI/MFMailComposeViewController.h> #import <MessageUI/MessageUI.h> @interface ViewController : UIViewController<MFMailComposeViewControllerDelegate> - (IBAction)SendMail:(id)sender; @end
.m文件里面实现为
- (IBAction)SendMail:(id)sender { MFMailComposeViewController *mailCompose = [[MFMailComposeViewController alloc] init]; if(mailCompose) { //设置代理 [mailCompose setMailComposeDelegate:self]; NSArray *toAddress = [NSArray arrayWithObject:@"Pleaseset@ToRecipients.com"]; NSArray *ccAddress = [NSArray arrayWithObject:@"Pleaseset@ccAddress.com"]; NSString *emailBody = @"The body of mail!"; //设置收件人 [mailCompose setToRecipients:toAddress]; //设置抄送人 [mailCompose setCcRecipients:ccAddress]; //设置邮件内容 [mailCompose setMessageBody:emailBody isHTML:YES]; //设置邮件主题 [mailCompose setSubject:@"The body of mail!"]; NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"testAVI" ofType:@".avi"]; NSArray *strArr = [videoPath componentsSeparatedByString:@"/"]; int temp=0; for (NSArray *secKey in strArr){ temp++; } NSString *Name = [NSString stringWithFormat:@"%@", [strArr objectAtIndex:temp-1]]; NSData *videoData = [NSData dataWithContentsOfFile: videoPath]; [mailCompose addAttachmentData:videoData mimeType:@"application/avi" fileName:Name]; //设置邮件视图在当前视图上显示方式 [self presentModalViewController:mailCompose animated:YES]; } return; }
这样就可以发送视频到邮件了,但是还需要一个代理,发送完退出present的邮件窗口;
- (void)alertWithTitle:(NSString *)title msg:(NSString *)msg { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { NSString *msg; switch (result) { case MFMailComposeResultCancelled: msg = NSLocalizedString(@"Sent cancel", @""); break; case MFMailComposeResultSaved: msg = NSLocalizedString(@"Save Successfull!", @""); [self alertWithTitle:nil msg:msg]; break; case MFMailComposeResultSent: msg = NSLocalizedString(@"Sent Successfull!", @""); [self alertWithTitle:nil msg:msg]; break; case MFMailComposeResultFailed: msg = NSLocalizedString(@"Sent Fail!", @""); [self alertWithTitle:nil msg:msg]; break; default: break; } [self dismissModalViewControllerAnimated:YES]; }
邮件分享是无法在模拟器上运行的,必须要真机,上面的代码,地址取的是外面拖进project的名字自动取得的,但是在app里面,我们如何取得app自己生成的地址呢?
这就需要 enumeratorAtPath 来遍历app中的视频
详细可见这篇博客
http://blog.csdn.net/p2game/article/details/17766427
由于本人技术有限,如有写的不科学的地方,还请指出来,大家一起交流!
如果大家有分享视频的好方法,也希望与博主分享一下,共同进步!
相关文章推荐
- C# APP.config
- 颠覆传统app格局的微信小程序来了:微信小程序开发环境搭建
- opencv-ios开发笔记11 亮度和色温调节
- Decompiled .class file,bytecode version:52.0(Java 8) Source for 'Android API 24 Platform' not found
- Android Easeui 3.0 即时通讯的问题汇总
- android监听应用自身被卸载
- php版微信自动登录并获取昵称的方法
- Android数据加密之SHA安全散列算法
- 微信小程序(应用号)开发体验
- Android数据加密之SHA安全散列算法
- Android manifest中强制设置横屏无效
- 安卓系统中调试webview页面的实践
- 关于Android Studio2.2版本logcat日志闪退显示不全的解决办法
- android 当中service的简单用法(用于消息推送)
- Unity3D 通用提示窗口实现分析(Inventory Pro学习总结)
- Appium自动化测试之Appium的安装与配置
- 微信小程序开发资源汇总 awesome-wechat-weapp
- BIOS入门之我见-I/O
- Android基础之屏幕适配
- Android 4.0 添加按键及KEY映射(转载)