Sharing UIImage to UIActivityViewController Twitter/Facebook very slow to show dialog
Asked Answered
O

1

6

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

Onslaught answered 25/2, 2015 at 21:20 Comment(3)
Just wanted to add that I am seeing this on iOS 8.4Terrorism
Hmm... This is a shame. Does the image actually get uploaded to Twitter fine then? It'd be good to upload user generated photos.Gaekwar
Also, is this performance issue still present in iOS 9?Gaekwar
V
1

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.

Valuate answered 12/2, 2016 at 15:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.