我正在尝试使用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) }