Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
791 views
in Technique[技术] by (71.8m points)

iphone - How to make the presentViewController with SLComposeViewController faster?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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];


});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...