最近在做一個無人機的項目 使用到的本地分享視頻,翻遍了友盟SDK以及ShareSDK 分享視頻都只支持文件方式分享。本應用只分享多為短視頻最后的結果是使用IOS自帶的UIDocumentInteractionController 實現本地視頻分享。
大致分三步實現
Step1: ViewControler 實現? <UIDocumentInteractionControllerDelegate>
Step 2: 獲取視頻文件地址
? ? NSString * filePath = [[NSBundle mainBundle] pathForResource:@"Test.mp4" ofType:nil];
? ? NSLog(@"Step 1: 獲取視頻文件地址 : %@",filePath);
Step 3: 初始化 及設置代理
? ? NSURL* url = [NSURLfileURLWithPath:filePath];
? ? self.docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
? ? self.docInteractionController.delegate = self;
Step 4: 顯示可以支持視頻的應用
? ? [self.docInteractionController presentOptionsMenuFromRect:self.view.frame? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? inView:self.view animated:YES];
Step 5:實現代理方法
#pragma mark - UIDocumentInteractionControllerDelegate
- (UIViewController*)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController*)interactionController
{
? ? return self;
}
參照例子?Demo