How to make currentViewController with SLComposeViewController faster?

I open the tweet viewer in my application, but the screen takes too long to display!

I started using the following code when the user clicked 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 5 to 8 seconds to display the screen! This is too long for me; I saw applications that go instantly. This is not a problem with my application, because I created a new project with only this functionality, and it accepts the same.

So, I thought that the delay was at the moment the screen was created, so I decided to declare my tweet screen on my header and moved this part to viewDidAppear:

 if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { tweet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; [tweet setInitialText:@"initial text "]; 

and by the button method:

 if(tweet) [self presentViewController:tweet animated:YES completion:^ { }]; 

but he did not speed up. I use iPhone 4 and I have some applications that very quickly create a screen for creating twitter. Does anyone know how to do this?

+4
source share
2 answers

I had the same problem - it drove me crazy. I fixed it dispatch_async in 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]; }); 
0
source

This problem also bugged me all day! Finally, I get some trick to make SLComposeViewController faster. It seems that when I want to load SLComposeVC for the first time, SLComposer will take up a lot of resources in the main thread, but after that its appearance will be completely normal without delay ... so, probably, we need to load SLCompose Look into our controller (just load the view ) and viola .. SLComposerView will be directly presented as ...

Just add this code to 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 am not a native.
0
source

Source: https://habr.com/ru/post/1447817/


All Articles