xcode – Swift 2 – 使用UIActivityViewController共享视​​频

前端之家收集整理的这篇文章主要介绍了xcode – Swift 2 – 使用UIActivityViewController共享视​​频前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用UIActivityViewController从URL共享视频.如果我尝试使用 Image,我没有问题.

分享图片作品:

let imageThump = NSURL(string: "https://example.com/image.png")
        let imageData = NSData(contentsOfURL: imageThump!) 
let objectsToShare = [comment!,imageData!]
            let activityVC = UIActivityViewController(activityItems: objectsToShare,applicationActivities: nil)

分享视频无效.为什么?

let videoShare = NSURL(string: "https://example.com/video.mp4")
        let videoData = NSData(contentsOfURL: videoShare!) 
let objectsToShare = [comment!,videoData!]
            let activityVC = UIActivityViewController(activityItems: objectsToShare,applicationActivities: nil)

解决方法

这就是你怎么做的….
let urlData = NSData(contentsOfURL: NSURL(string:"https://example.com/video.mov)")!)

            if ((urlData) != nil){

                print(urlData)


                let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)
                let docDirectory = paths[0]
                let filePath = "\(docDirectory)/tmpVideo.mov"
                urlData?.writeToFile(filePath,atomically: true)
                // file saved

                let videoLink = NSURL(fileURLWithPath: filePath)


                let objectsToShare = [videoLink] //comment!,imageData!,myWebsite!]
                let activityVC = UIActivityViewController(activityItems: objectsToShare,applicationActivities: nil)

                activityVC.setValue("Video",forKey: "subject")


                //New Excluded Activities Code
                if #available(iOS 9.0,*) {
                    activityVC.excludedActivityTypes = [UIActivityTypeAirDrop,UIActivityTypeAddToReadingList,UIActivityTypeAssignToContact,UIActivityTypeCopyToPasteboard,UIActivityTypeMail,UIActivityTypeMessage,UIActivityTypeOpenInIBooks,UIActivityTypePostToTencentWeibo,UIActivityTypePostToVimeo,UIActivityTypePostToWeibo,UIActivityTypePrint]
                } else {
                    // Fallback on earlier versions
                    activityVC.excludedActivityTypes = [UIActivityTypeAirDrop,UIActivityTypePrint ]
                }


                self.presentViewController(activityVC,animated: true,completion: nil)
            }
原文链接:https://www.f2er.com/iOS/331202.html

猜你在找的iOS相关文章