Search code examples
iostwittergifslcomposeviewcontroller

Post animated gif on Twitter with SLComposeViewController


Twitter now supports posting animated gifs. see: https://twitter.com/Support/status/479307198901026816 However I've been trying to post an animated gif to twitter using the SLComposeViewController but the gif gets flattened to a single frame.

NSData *data = [NSData dataWithContentsOfFile:self.filepath];    
UIImage *gif = [UIImage imageWithData:data];

SLComposeViewController *sheet = [SLComposeViewController composeViewControllerForServiceType:serviceType];
[sheet setInitialText:[NSString stringWithFormat:@"Just created a Gif"]];
[sheet addImage:gif];
[self presentViewController:sheet animated:YES completion:nil];

Solution

  • You can use SLRequest, a lower-level way of accessing the API through the Twitter API itself, to accomplish this.

    You're going to have to wait until Apple implements support for animated GIFs if you want to use SLComposeViewController - this likely isn't something that you're going to be able to fix in your code.