6

I have a UIActivityViewController sharing an object that

  • conforms to the UIActivityItemSource protocol and
  • offers an animated GIF file by returning an NSURL of a .gif file and CFBridgingRelease(kUTTypeGIF) in the appropriate methods.

I see the GIF moving in the Simulator if I share one of my objects in a new Mail message. If I try tweeting the same thing, a frame of the image is attached to the tweet, but it's uploaded as a still image.

Do I need to wait for Apple to update UIActivityTypePostToTwitter in a future iOS version, or have I missed a workaround you've seen somewhere? (I realize this case isn't using anything from the list "Twitter.com, Android and iPhone [app]". This is probably a futile plea.)

Homework already done:

  • I know that the Twitter activity type can also work with an ALAsset object, and people get animated gifs into and out of Saved Photos by keeping their data wrapped up in ALAssets, but I want to be able to tweet these gifs without touching the Camera Roll, if possible.
  • I checked NSHipster.
  • I tried returning an NSData object instead of an NSURL for my local .gif file on a tip from Lyndsey about the Twitter API. No change.
  • I tried returning kUTTypeData instead of kUTTypeGIF as the dataTypeIdentifierForActivityType after seeing this in the Twitter API docs:

    The image passed should be the raw binary of the image or binary base64 encoded, no need to otherwise encode or escape the contents as long as the Content-Type is set appropriately (when in doubt: “application/octet-stream”).

    but then no image appeared in my tweet.

Thanks!

origamike
  • 71
  • 5
  • I'm not sure if it's Apple that is preventing this. It might be the Twitter host API that doesn't accept animated GIF images from Apple. Does Twitter accept animated GIFs from browser-based clients or from other native mobile clients (on say, Android or Windows Mobile?) – Duncan C Jun 23 '14 at 01:18
  • Are you posting the image as data or as an URL? – Lyndsey Scott Jun 23 '14 at 01:44
  • @DuncanC, Twitter does allow them from the browser and their Android app. – origamike Jun 23 '14 at 04:53
  • @LyndseyScott, as a URL for the local .gif file – origamike Jun 23 '14 at 04:54
  • 1
    @origamike Hey, have you found a solution? – Andrey Tarantsov Jul 31 '14 at 13:13
  • @AndreyTarantsov Nope, not yet. I suspect Apple needs to update UIActivityTypePostToTwitter for this to work without hacking around it. – origamike Jul 31 '14 at 17:11
  • i have found what appears to be a bug: if you do NOT have native twitter app installed, but DO have twitter accounts configured, using the `NSData` approach produces [working GIFs](https://twitter.com/mgiraldo/status/671868797771456512). i use Tweetbot so i didn't notice this problem at first but then another beta tester had your same problem and i could reproduce it. let me know if you figure out a workaround to this. – mga Dec 02 '15 at 17:18
  • Anyone got a solution? [SteppyPants](http://steppypants.com/) seems already able to make it. – Richard Fu Jun 14 '16 at 08:31

2 Answers2

0

As listed under "parameters" of the Twitter API:

image: The background image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be forcibly scaled down. The image must be provided as raw multipart data, not a URL.

Lyndsey Scott
  • 37,080
  • 10
  • 92
  • 128
  • 2
    Thanks for digging, Lyndsey. Those size limits don't apply to tweeted images, but on the chance that "raw data" was a hint, I've tried providing the UIActivityItem as an NSData object instead of NSURL, but the same thing happens: Twitter uploads a still image. My understanding is that `UIActivityTypePostToTwitter` exists to abstract away the Twitter API's requirements, and it's not ready for animated GIFs yet. – origamike Jun 23 '14 at 16:07
  • Although that's not exactly addressing the question, but I've tested and confirmed that UIActivityViewController uploaded GIF can be successfully animated when it's under ~100kb, otherwise it get "scaled down" to a JPG..... – Richard Fu Jul 08 '16 at 02:10
  • @RichardFu It seems as if I was directly addressing the conversation in the comment thread: "Are you posting the image as data or as an URL? – Lyndsey Scott Jun 23 '14 at 1:44" "@LyndseyScott, as a URL for the local .gif file – origamike Jun 23 '14 at 4:54" But it also seems as if origamike's size limit comment under this answer was incorrect and the entire blurb I posted needs to be followed so the gif isn't forcibly scaled down into a jpg. – Lyndsey Scott Jul 09 '16 at 13:05
0

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.

- (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