Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Share GIF (animated image) not Working

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.

like image 992
Sattar Avatar asked May 03 '16 14:05

Sattar


People also ask

Why can't I send a GIF in a text message iPhone?

The simplest solution if the GIF Search isn't working is to re-add the #Images app to the iMessage apps. #Images is the built-in GIF app for iMessage which you use to send GIFs. Open the Messages app and go to any conversation. Scroll right on the iMessage app bar and tap the App Drawer (the More option).

Why are my GIF not moving?

If your GIF file is not playing or looping, it might be because the file is too large. If it's more than 1080 pixels high or 1920 pixels wide, you'll need to reduce the size. There are a number of free, online tools of varying sophistication that you can use.


2 Answers

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.

like image 70
Sattar Avatar answered Oct 13 '22 13:10

Sattar


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

like image 21
Richard Fu Avatar answered Oct 13 '22 12:10

Richard Fu