UIActivityViewController分享視訊到第三方App
一、分享視訊到App,AirPort、郵件等
NSString *localPath = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"MP4"];
NSURL *urlPath1 = [NSURL fileURLWithPath:localPath];
NSURL *urlPath2 = [NSURL URLWithString:localPath];
//urlPath1 = @"file:///var/containers/Bundle/Application/56D4C879-4242-44ED-877A-255C9BAD87AA/ActivityAirPortDemo.app/test.MP4";
//urlPath2 = @"/var/containers/Bundle/Application/56D4C879-4242-44ED-877A-255C9BAD87AA/ActivityAirPortDemo.app/test.MP4";
1.items
//需要分享的內容: 標題、圖片、url
NSMutableArray *items = [[NSMutableArray alloc] init];
if (title) {
[items addObject:title];
}
if (image) {
[items addObject:image];
}
NSString *localPath = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"MP4"];
if (localPath) {
//*** 這裡URL是用[NSURL fileURLWithPath:localPath]; ***
NSURL *urlPath = [NSURL fileURLWithPath:localPath];
[items addObject:urlPath];
}
2.activities
//自定義“分享目標icon”
NSMutableArray *activities = [[NSMutableArray alloc] init];
//youtube
HBShareBaseActivity *youtubeActivity = [[HBShareBaseActivity alloc] initWithTitle:@"YouTube" type:kYouTubeType path:_localPath];
//mail
HBShareBaseActivity *mailActivity = [[HBShareBaseActivity alloc] initWithTitle:NSLocalizedString(@"bc.player.share_mail_title", 0) type:UIActivityTypeMail path:_localPath];//
//
[@[mailActivity, youtubeActivity] enumerateObjectsUsingBlock:^(HBShareBaseActivity *activity, NSUInteger idx, BOOL *stop) {
activity.shareDescription = description;
activity.shareTitle = title;
activity.shareImage = image;
}];
[activities addObjectsFromArray:@[mailActivity, youtubeActivity]]; //
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:activities];
//需要遮蔽的系統分享
NSArray *excludedActivityTypes = @[UIActivityTypePostToFacebook,
UIActivityTypePostToTwitter,
UIActivityTypePostToWeibo,
UIActivityTypeMessage,
UIActivityTypeMail,
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,
//UIActivityTypeAirDrop,
UIActivityTypeOpenInIBooks,
//UIActivityTypeMarkupAsPDF
];
activityViewController.excludedActivityTypes = excludedActivityTypes;
AppDelegate *iApp = (AppDelegate*)[UIApplication sharedApplication].delegate;
[iApp.window.rootViewController presentViewController:activityViewController animated:YES completion:nil];
//[UIViewController.topVC presentViewController:activityViewController animated:YES completion:nil];
activityViewController.completionWithItemsHandler = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
NSLog(@"social share activityType=%@, returnedItems=%@", activityType, returnedItems);
if (completionHandler) {
completionHandler(activityType, completed);
self.completionHandler = nil;
}
};
二、MFMailComposeViewController傳送郵件
- (void)sendMailAction {
//附件
NSData* pData = [[NSData alloc]initWithContentsOfFile:self.urlPath];
if (pData) {
MFMailComposeViewController *mailCompose = [[MFMailComposeViewController alloc] init];
_mailCompose = mailCompose;
if(mailCompose) {
//設定代理
[mailCompose setMailComposeDelegate:self];
NSArray *toAddress = [NSArray arrayWithObject:@""]; //收件人
NSArray *ccAddress = [NSArray arrayWithObject:@""]; //抄送人
NSString *emailBody = @"<H1></H1>"; //郵件內容
//設定收件人
[mailCompose setToRecipients:toAddress];
//設定抄送人
[mailCompose setCcRecipients:ccAddress];
//設定郵件內容
[mailCompose setMessageBody:emailBody isHTML:YES];
//設定郵件主題
[mailCompose setSubject:@""]; //郵件主題 email title
//設定郵件附件{mimeType:檔案格式|fileName:檔名}
NSString *lastName = [_urlPath componentsSeparatedByString:@"/"].lastObject;
NSString *fileExtension = [lastName componentsSeparatedByString:@"."].lastObject;
if (!lastName) {
lastName = @"test.mp4";
}
if (!fileExtension) {
fileExtension = @"mp4";
}
[mailCompose addAttachmentData:pData mimeType:fileExtension fileName:lastName];
//設定郵件檢視在當前檢視上顯示方式
AppDelegate *iApp = (AppDelegate*)[UIApplication sharedApplication].delegate;
[iApp.window.rootViewController presentViewController:mailCompose animated:YES completion:nil];
//[UIViewController.topVC presentViewController:mailCompose animated:YES completion:nil];
}
return;
}
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
NSString *msg = nil;
switch (result) {
case MFMailComposeResultCancelled:
msg = @"郵件傳送取消";
break;
case MFMailComposeResultSaved:
msg = @"郵件儲存成功";
break;
case MFMailComposeResultSent:
msg = @"郵件傳送成功";
break;
case MFMailComposeResultFailed:
msg = @"郵件傳送失敗";
break;
default:
break;
}
NSLog(@"傳送郵件: %@", msg);
[_mailCompose dismissViewControllerAnimated:YES completion:nil];
}
相關文章
- 14.iOS原生分享:UIActivityViewController,分享到微信失敗iOSUIViewController
- ReactNative乾貨分享——視訊播放器AppReact播放器APP
- flashback視訊分享
- 從 Flutter 的視訊渲染到 App 落地經驗FlutterAPP
- IOS 系統自帶的分享功能之 UIActivityViewControlleriOSUIViewController
- 【視訊分享】尚矽谷Java視訊教程_DubboJava
- 視訊分享平臺
- uni-app技術分享| uni-app轉小程式_實時音視訊APP
- 【5+App】第三方分享的思路APP
- 前端視訊資源分享前端
- undo和lock視訊分享
- thinkphp視訊商城原始碼分享PHP原始碼
- App視訊邀請功能APP
- 視訊投影(二維視訊投影到三維模型上)模型
- 分享51CTO swift視訊教程!!Swift
- Symfony Bundle開發視訊教程分享
- statspack、awr、addm,ash視訊分享
- Android逆向之旅--微信封了抖音分享功能,而我要把短視訊成功分享到朋友圈!...Android
- 短視訊app開發,長按將視訊儲存到相簿APP
- Python從入門到精通視訊(全60集)馬哥教育視訊(已修復部分視訊無聲音的問題+其他優化)+筆記分享Python優化筆記
- 優秀第三方庫-視訊播放器播放器
- 短視訊如何寫爆款文案?爆款短視訊文案技巧分享
- 新手怎麼運營短視訊?短視訊運營幹貨分享
- web技術支援| 從視訊元素流式傳輸到視訊元素Web
- 短視訊app開發,點選視訊進行全屏播放APP
- 直播短視訊原始碼短視訊APP短視訊帶貨系統多商戶直播原始碼APP
- 短視訊app開發之ios小視訊開發經驗共享APPiOS
- uni-app視訊教程合集|UniApp實戰教程APP
- GopherChina 2017 分享視訊和 PPTGo
- 分享 Laravel 中使用 vuejs 教學視訊LaravelVueJS
- 尚矽谷springboot視訊資料分享Spring Boot
- Altium.Designer的學習視訊 分享~~
- 嵌入視訊到html5頁面HTML
- Cordova開發app——短視訊拍攝APP
- GopherChina 2016 分享視訊和 PPTGo
- 最新最全的 layUI 框架使用教程視訊教程分享UI框架
- 萬彩動畫大師教程 | 如何分享動畫視訊?動畫
- 短視訊開發app,自定義帶進度條的視訊播放按鈕APP