How to make the presentViewController with SLComposeViewController faster?

前端 未结 2 988
轻奢々
轻奢々 2020-12-19 16:39

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 but

相关标签:
2条回答
  • 2020-12-19 17:06

    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];
    
    
    });
    
    0 讨论(0)
  • 2020-12-19 17:07

    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.
    0 讨论(0)
提交回复
热议问题