6

I have some sharing code that works fine for iOS 7, but as of iOS 8, no longer works.

@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 stated, this is working fine in iOS 7, but as of iOS 8, the video clip is no longer attached to the post (or visible in the share panel) when I choose to share to Facebook. All other options work, Mail, Save to Video, AirDrop, etc all seem to work fine.

I've also tried passing the items as AVAssets:

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

and NSData:

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

Neither of which had any effect on the problem.

The problem also occurs if I use the moral equivalent in Objective-C, it's language agnostic.

David Berry
  • 40,941
  • 12
  • 84
  • 95

2 Answers2

4

I got the same problem and I found the key point is the file type. I have tried to share a .mp4 video, it won't attach video to the post. Once I use .mov video, it works for me.

Ocean Lin
  • 41
  • 2
  • 1
    @JamesWoolfenden I am confused by your comment. How is Ocean Lin's answer considered not an answer to the question? The question was how to fix FB sharing that isn't working in iOS8. Ocean Lin's answer is to look at whether it is because sharing isn't working for mp4 files in iOS8 but *is* working for .mov files. How is that not helpful? – Praxiteles Jul 04 '15 at 17:48
1

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

I had video data that I first saved to a file in documents directory and then I attached that 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];
}
Jason
  • 11,744
  • 3
  • 42
  • 46
tjay
  • 21
  • 2
  • In my case they're already file urls. I've tried it with them located in both the application resources and inthe documents directory, it makes no difference. The major difference I see is that I'm using an mp4 and you're using a .mov – David Berry Oct 02 '14 at 06:21