Share videos on Facebook on iOS 8

I have an exchange code that works great for iOS 7, but doesn't work with iOS 8 anymore.

@IBAction func onShareButton(sender: UIButton) { let movie = NSBundle.mainBundle().URLForResource("IMG_0564", withExtension: "mp4")! let items = [movie] let activity = UIActivityViewController(activityItems: items, applicationActivities: nil) if activity.respondsToSelector("popoverPresentationController") { activity.popoverPresentationController?.sourceView = sender } self.presentViewController(activity, animated: true, completion: nil) } 

As I said, this works fine in iOS 7, but with iOS 8 the video clip is no longer attached to the message (or displayed on the sharing panel) when I decided to share it with Facebook. All other work options, Mail, Save to video, AirDrop, etc., It seems to work fine.

I also tried passing items as AVAssets:

  let items = [movie].map { AVAsset.assetWithURL($0) } 

and NSData:

  let items = [movie].map { NSData(contentsOfURL: $0) } 

None of them affected the problem.

The problem also arises if I use the moral equivalent in Objective-C, it is an agnostic language.

+6
source share
2 answers

I have the same problem and I found the key point - this is the file type. I tried to share the .mp4 video, it will not attach the video to the message. When I use .mov video, it works for me.

+4
source

Ok, I tried a workaround and it worked for me.

I had video data that I first saved to a file in the document directory, and then I attached this file.

 //write to a file [videoData writeToFile:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.mov"] atomically:YES]; - (IBAction)ShareVideoWihFacebook:(id)sender { //get the file url NSString* path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.mov"]; NSURL *videoURL = [NSURL fileURLWithPath:path]; UIActivityViewController * activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[videoURL,@"Created by ..."] applicationActivities:NULL]; [activityVC setExcludedActivityTypes:@[ UIActivityTypeMail,UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePrint, UIActivityTypePostToWeibo,UIActivityTypeMessage,UIActivityTypeAirDrop,UIActivityTypeSaveToCameraRoll]]; [activityVC setValue:@"My Video" forKey:@"subject"]; [activityVC setCompletionHandler:^(NSString *activityType, BOOL completed) { //NSLog(@"completed dialog - activity: %@ - finished flag: %d", activityType, completed); }]; [self presentViewController:activityVC animated:TRUE completion:nil]; } 
+1
source

Source: https://habr.com/ru/post/975324/


All Articles