Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

objective c - Prompt login alert with Twitter framework in iOS5?

As you all may know, since iOS5 there is a native Twitter framework which make it easy to post tweets from your app.

Is there a way to prompt an alert that forwards the user to the settings app and ask for username and password?

I know that i could solve the problem with the following code:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];

But thats undocumented code..

Thanks in advance

Regards Billy (My first post on SO)

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

In iOS5.1, we should use TWTweetComposeViewController to show the dialog since apple rejects apps using prefs:root=TWITTER.

But, I didn't like showing the tweet screen and keyboard
so I figured out the way to hide them, but show the pop up screen.

UPDATE: Apple approved my app using this trick.


enter image description here

    TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];

    //hide the tweet screen
    viewController.view.hidden = YES;

    //fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
    viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
        if (result == TWTweetComposeViewControllerResultCancelled) {            
            [self dismissModalViewControllerAnimated:NO];
        }
    };
    [self presentModalViewController:viewController animated:NO];

    //hide the keyboard
    [viewController.view endEditing:YES];

    //this approach doesn't work since you can't jump to settings
//    [self dismissModalViewControllerAnimated:NO];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...