6

It's been almost 2 days that i'm looking to find a solution to my problem but i wasn't successful , i want to share GIF (animated image) on Facebook, Twitter, Email, WhatsApp , using "UIActivityViewController".

This is my code :

NSURL *imagePath = [NSURL URLWithString:@"http://sth.gif"];
NSData *animatedGif = [NSData dataWithContentsOfURL:imagePath];

NSArray *sharingItems = [NSArray arrayWithObjects: animatedGif,stringToShare, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];

When i share in Email its animated and its working perfect , but in Twitter , Facebook , whatsApp Gifs are not animated and its like an image ... I already read all Stack-overflow questions about the same problem Like this or this or this but its not working for me.

Community
  • 1
  • 1
Sattar
  • 393
  • 5
  • 18

3 Answers3

3

So far base on days research found out that :

TWITTER : For share a GIF on twitter had to use twitter API and create a multipart request to achieve the goal and its working very well.

FACEBOOK : I did share some GIF on Facebook using FACEBOOKSHAREKIT , but i don't know why sometimes Gifs are animated, sometimes not.

INSTAGRAM : To share gif on Instagram had to convert GIFS to MP4 (or any other video formats accepted by Instagram) then save it into camera roll then share it , It is little twisted but its working very well.

WHATSAPP : It not supporting GIF at all. READ THE UPDATE

To do all of this i couldn't use "UIActivityViewController" , so decided to create a custom share page. if anybody know something to add here , to help me and others please tell me (especially about Facebook). Thanks in advance

UPDATE

WHATSAPP : Thanks to @AmmarShahid, as he mentioned in comments, Whatsapp now supports gif.

Sattar
  • 393
  • 5
  • 18
1

Encountered the similar problem and Googled a lot but still not a perfect solution, the best I came up is here:

Use UIActivityItemProvider and extend - (id)item {} for different UIActivityType:

Twitter: The default UIActivityViewController Twitter share doesn't support it yet which it will "scale down" it as a still JPG. However somehow it works for GIF less than 100kb (tested in iOS 9) and I don't know why. Therefore, I have to use SLRequest to upload the GIF as taught in here. When the SLRequest is done and return, dismiss the UIActivityViewController. The downside of that is no preview share sheet and users cannot type their own message anymore.

Facebook: It's actually much easier! Just upload the GIF to Giphy, then provide the Giphy URL to UIActivityViewController instead of the file contents, Facebook will recognize it and show the animated GIF

- (id)item
{    
    if ([self.activityType isEqualToString:UIActivityTypePostToFacebook]) {
        // Upload to Giphy
        ...
        return [NSURL URLWithString:giphyURL];
    }
    if ([self.activityType isEqualToString:UIActivityTypePostToTwitter]) {
        // Use SLRequest to share instead
        ...
        // Dismiss the UIActivityViewController (I am using Unity)
        [UnityGetGLViewController() dismissViewControllerAnimated:NO completion: NULL];
        return nil;
    }
}

full code is in my GitHub, I am actually a iOS newb so some experts please correct me and the code if possible

Richard Fu
  • 616
  • 10
  • 27
  • Your solution for facebook is good, unfortunately up to now this is the only way to share gifs on facebook . – Sattar Jul 14 '16 at 16:06
0

// Share GIF File: WhatsApp

    NSURL *imageUrl =[self.ImageArray objectAtIndex:currentPhotoIndex];
    NSString *path=imageUrl.absoluteString;
    NSArray *strings = [path componentsSeparatedByString:@"/"];
    NSString *mygif=[strings objectAtIndex:strings.count-1];

    NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *dataPath = [documentsPath stringByAppendingPathComponent:@"/MrHRamani"];

    NSString *filePath = [dataPath stringByAppendingPathComponent:mygif];

    NSURL *urll=[NSURL fileURLWithPath:filePath];
    NSLog(@"imag %@",imageUrl);
    self.documentationInteractionController.delegate = self;
    self.documentationInteractionController.UTI = @"net.whatsapp.image";
    self.documentationInteractionController = [self setupControllerWithURL:urll usingDelegate:self];
    [self.documentationInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
Ramani Hitesh
  • 214
  • 3
  • 15