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

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

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.

Related

UIActivityViewController not sharing animated GIF to Twitter

I am unable to share an animated GIF via the UIActivityViewController and the Twitter app. The result I get is a static image, the first frame of the animation.
Using the same UIActivityViewController, I am able to share the animated GIF via Slack, Facebook Messenger, and the Messages app. Twitter seems to be the exception.
The GIF is stored as an NSData object. I am initializing the activity controller and passing the object to it. The image is about 700kb total - well beneath the 5mb cap on mobile.
This was done using an iPhone X, using iOS 12.2
[self.view animatedGif:^(NSData *gifData) {
// make sure we perform UI changes on the main thread via GCD
dispatch_async(dispatch_get_main_queue(), ^{
UIActivityViewController *avc = [[UIActivityViewController alloc]
initWithActivityItems:#[gifData]
applicationActivities:nil];
[self presentViewController:avc animated:YES completion:nil];
});
}];
Twitter only displays the result as a single image - the first frame of the animation. How can I get it to send and display the entire animation?

SLComposeViewController does not share image and url together

I am trying to share a photo and URL on facebook using SLComposeViewController. Only the URL shows up in either the preview, and in the newsfeed.
If I share an image only, it works fine: image appears on the feed
If I share URL only, same result as when I do both, URL is shared to feed
I am fully aware that as per Facebook policy, initial text gets nuked, no matter what you put there, but this problem is not about that
I have exact same results with using directly FBSDKShareLinkContent or FBSDKSharePhotoContent
Seems like URL is overwriting whatever image content you want to share. I am using iOS 9.2, with Facebook app 50.0 installed on the device
Here is the code I am using:
SLComposeViewController *fbController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
//setting completion handler omitted
[fbController addImage:self.image]; //any image
[fbController addURL:[NSURL URLWithString:url]];
[self presentViewController:fbController animated:YES completion:nil];
Any ideas how to solve this?

Laggy presentation of SLServiceTypeFacebook

so I'm making a post to Facebook and want the user to select an image before doing that.
Once the image is picked and I show Facebook. Problem is, when I show Facebook straight away, without the image picking part, it looks fine. When I show it after picking the image, Facebook sharing appears animated, but laggy. As if the action has a very low framerate or something.
Here's my code:
self.portraitPicker = [[UIImagePickerController alloc] init];
#if !(TARGET_IPHONE_SIMULATOR)
self.portraitPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
#endif
[self.portraitPicker setDelegate:self];
self.portraitPicker.allowsEditing = YES;
[self presentViewController:self.portraitPicker animated:YES completion:nil];
Now when this is complete, I show the Facebook posting modally:
[picker dismissViewControllerAnimated:YES completion:^{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
self.facebookController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[self.facebookController setInitialText:#"Some text"];
[facebookController addImage:pickedImage];
[self presentViewController:self.facebookController animated:NO completion:nil];
}
}];
I can do this in the didFinishPickingMediaWithInfo or the imagePickerControllerDidCancel, doesn't matter, the problem still comes up.
Being desperate, I tried:
Showing it on the main thread delayed
Showing it async
Showing it outside the dismiss-block
Showing it from the AppDelegate's rootviewcontroller instead
This is not Facebook-related as it happens with SLServiceTypeTwitter as well as with MFMessageComposeViewController.
Can't seem to do away with the laggy animation that ONLY happens showing the image picker. Does anyone know what's causing this?
Given the lack of response and similar issues, I figured the cause was my own architecture.
It turns out that one of my viewcontrollers' ViewDidAppear was called after the camera picker was displayed (as it became the active viewcontroller and consequently the inactive one, giving control back to the original viewcontroller).
Blocking the background calls and animation that happened in this viewDidAppear resolved the issue. I still don't know why calling it delayed (i.e. 10 seconds, or even 100 seconds into the future, when nothing was going on) still had the laggy appearence show up, but there it is.

ios implement video share which loacate in Photos

I use UIActivityViewController to implement eMail and Message.
NSArray *activityItems;
activityItems = #[[self.mURL path],self.mURL];
UIActivityViewController *activityController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:nil];
[self presentViewController:activityController
animated:YES completion:nil];
But how can I implement below view, especially youtube, youku, and tudou on iOS6?
Your app will have to provide a custom UIActivity that handles URLs and file paths. For an example, see my book: http://www.apeth.com/iOSBook/ch26.html#_activity_view
Look about halfway through that section, where I create a custom activity called Be Cool.
What you will actually do with the URL (i.e. how you are going to get this video sent to YouTube, or whatever it is you are trying to do) is entirely up to you.

iOS 5: Twitter composer view appears slowly

I have a question about presenting the TWTweetComposerViewController as a modal view in iOS 5.
I use the apple sample code as below to implement a tweet method in my app.
-(void)tweet
{
//Using tweeting example code.
//Setup the build-in twitter composer view controller
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc]init];
//Add url
[tweetViewController addURL:[self URL]];
[tweetViewController setInitialText:#""];
//Present Composer
[self presentModalViewController:tweetViewController animated:YES];
//Creat the completion handler
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result)
{
//Do something here.
[self dismissModalViewControllerAnimated:YES];
}];
[tweetViewController release];
}
This works fine, when I call the tweet method, the tweet controller does appear as a modal view.
However, the problem is: the composer shows up very slowly. It usually takes 3-5 seconds to show the composer. Of course, this is when the app calls this method for the first time. After the first time, it shows up a little bit quicker, but still take about 1~2 seconds.
I wonder if is there something I didn't do right to make the composer view appear slowly? Is there any way to speed up the process?
Btw. the testing device is the iPhone 4.
Thanks!
Yes, there is. You can preload the class by initializing it in the background sometime before you'll ever need it. Move tweetViewController into an instance or static variable, initialize and set all of its properties. Then just show it in the tweet method.

Resources