I am opening the Twitter compose view on my app, but the screen takes too long to be displayed!
I started using the following code when the user taps the twitter button:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweet setInitialText:@"initial text "];
[self presentViewController:tweet animated:YES completion:^
{
}];
}
But it takes between 5 and 8 seconds to show the screen! For me it's too long, I saw apps that goes instantly. It is not an issue with my app, because I have created a new project with only this functionality, and it takes the same.
So I thought that the delay was in the moment that the screen is instantiated, so I have decided to declare my tweet screen on my header and moved this part to the viewDidAppear:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
tweet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweet setInitialText:@"initial text "];
and on the button method is like that:
if(tweet)
[self presentViewController:tweet animated:YES completion:^
{
}];
but it didn't get faster. I am using an iPhone 4 and I have some apps that creates the twitter compose screen really fast, does anybody know how to do that?
I had the same issue -- it was driving me crazy. I fixed it by dispatch_async on the main queue
// Perform this on the main queue
__weak __typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
__strong __typeof(self) strongLocalSelf = weakSelf;
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:@"Share message"];
[controller addURL:@"http://www.someURL.com"];
[strongLocalSelf presentViewController:controller animated:NO completion:nil];
});
This issue has been bugging me as well for a whole day! Finally i get some trick to make the SLComposeViewController appear faster. Its seems when I want to load the SLComposeVC for the first time, The SLComposer will take a lot of resource in main thread, but after that, its will appear perfectly normal without delay... so I guess maybe we need to load the SLCompose View in our view controller (just load the view) and viola.. the SLComposerView will be directly presented into the view...
Just add this code in your appdelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ ....
//loading the view...make twitter share dialog appear with no dellay
if(NSClassFromString(@"SLComposeViewController") != nil){
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composeViewController view];
}
...
}
- sorry if my English is not perfect, I'm not a native.
来源:https://stackoverflow.com/questions/13519904/how-to-make-the-presentviewcontroller-with-slcomposeviewcontroller-faster