Open Twitter app from my iOS 5 app

Go To


I am trying to open the Twitter app from within my app in iOS 5, but it won't open. Any help would be appreciated, I have included the code I am using below.

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

Please help me, and thanks in advance!

2012-04-04 04:36
by Muhammad Jabbar


Do you want to launch the Twitter app, Or just send tweets from within your app? I believe that the code you are showing above is to Launch Twitters preferences in your settings app... Which I also believe has been disallowed in 5.1

If you are looking to add Twitter integration to your app Apple provides great sample code to show you how to use Twitter with the built in Twitter frameworks in iOS 5.

Now I recommend you download this sample code and see what else is required to send a tweet (like checking CanTweetStatus) but I'm attaching a basic idea of how to send a tweet in this post.

- (IBAction)sendCustomTweet:(id)sender {
    // Create an account store object.
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    // Create an account type that ensures Twitter accounts are retrieved.
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    // Request access from the user to use their Twitter accounts.
    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
        if(granted) {
            // Get the list of Twitter accounts.
            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

            // For the sake of brevity, we'll assume there is only one Twitter account present.
            // You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
            if ([accountsArray count] > 0) {
                // Grab the initial Twitter account to tweet from.
                ACAccount *twitterAccount = [accountsArray objectAtIndex:0];

                // Create a request, which in this example, posts a tweet to the user's timeline.
                // This example uses version 1 of the Twitter API.
                // This may need to be changed to whichever version is currently appropriate.
                TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@""] parameters:[NSDictionary dictionaryWithObject:@"Hello. This is a tweet." forKey:@"status"] requestMethod:TWRequestMethodPOST];

                // Set the account used to post the tweet.
                [postRequest setAccount:twitterAccount];

                // Perform the request created above and create a handler block to handle the response.
                [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                    NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                    [self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO];

Good Luck!

2012-04-04 05:15
by Mick MacCallum


If you are just trying to open the actual Twitter app then the code is

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://"]];
2012-04-04 05:52
by Otium
it is opening twitter app not TWITTER Setting - PJR 2012-07-04 08:20
It is not allowed to open preferences from app - Otium 2012-07-04 21:02