Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing UIImage to UIActivityViewController Twitter/Facebook very slow to show dialog

I have an image I took from the camera and saved to the /tmp folder.

When I add this image to the activityItems of an UIActivityViewController, and then press to share with either Twitter or Facebook, I have to wait up to 20 seconds for the share dialog to appear.

Note that I'm referring to the actual "Post" dialog that appears for Twitter/Facebook, not the native share popup that spawns it.

When I share the same image from the Photos app, it appears instantly.

At first I was thinking the Photos app was resizing the image, as a smaller image appears more quickly, but than I discovered that when I share the same image directly to Twitter or Facebook with SLComposeViewController, it appears (almost) instantly.

Assuming it's something I'm doing incorrectly in code, here is what results in the glacially slow dialog appearance:

NSArray *items = @[@"foo", [UIImage imageWithContentsOfFile:@"valid path to test image"]];

UIActivityViewController *vc = [[UIActivityViewController alloc]
        initWithActivityItems:items applicationActivities:nil];
[self presentViewController:vc animated:YES completion:nil];

Here's what works almost instantly:

SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[controller setInitialText:@"foo"];
[controller addImage:[UIImage imageWithContentsOfFile:@"valid path to test image"]];
[self presentViewController:controller animated:YES completion:Nil];

For what it's worth, I've also tried excluding the other share types (I read that in the past AirDrop caused issues), as well as wrapping the block to ensure I was executing on the main thread.

I assume I'm doing something wrong?

If I'm not, and these two other methods are in fact resizing the image, is there some documentation I'm missing that provides guidance as to how much resizing to do?

** Edit: additional testing seems to show this problem is unique to iOS8, as I did not experience it on an older iOS7 device.

Thanks

like image 959
Jason Avatar asked Feb 25 '15 21:02

Jason


1 Answers

We've seen 4–20 seconds delay before the share dialog appear as well!.
I've fixed it by creating custom UIActivity items for Twitter and Facebook which simply calls SLComposeViewController inside performActivity method.

Seems much faster.

like image 110
Pavel Alexeev Avatar answered Oct 20 '22 22:10

Pavel Alexeev