How to make the presentViewController with SLComposeViewController faster?

落花浮王杯 提交于 2019-11-29 11:31:44

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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!