Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Twitter Setting from ACAccountStore (iOS 5.1 TWITTER)

in iOS 5.0 i was opening Twitter setting from my app by

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

but , this features is removed in iOS 5.1 , hence i can not able to open twitter setting .

Now i am using

 + (void)makeRequestsWithURL: (NSURL *)url {
// 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];
[self canTweetStatus];

// 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:url parameters:nil 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]];
                iOS5Twitter *twitter5 = [[iOS5Twitter alloc] init];
                [twitter5 performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO];
                [twitter5 release];                }];
        }
    }

}];

}

for making request, i am able to check wether i am loged in or not by the

if ([TWTweetComposeViewController canSendTweet])

but now i want : if i am not loged in it would be show an alert like shown in image and want to move to the twitter setting . is it possible ? or i have to manually go ti twitter setting ?enter image description here

like image 715
PJR Avatar asked Jul 04 '12 08:07

PJR


People also ask

Is Twitter available for iOS?

The Twitter for iOS app can be used on an iPhone, iPad, or iPod Touch device.

How do I reduce the size of the twitter app?

You should delete your Twitter cache to save space on your phone, helping it operate more efficiently and freeing up space on your iPhone or Android. Note that everytime you scroll through Twitter the cache will fill up again. For that reason, you should regularly empty your cache.


2 Answers

It is little tricky , i get by the removing the subviews in *TWTWeetComposeViewController*, so it shows only alert when user is not loged in and by the clicking on setting button , we can open Setting page in my app.

     + (void)setAlertForSettingPage :(id)delegate 
    {
     // Set up the built-in twitter composition view controller.
        TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];


        // Create the completion handler block.
        [tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
            [delegate dismissModalViewControllerAnimated:YES];
        }];

        // Present the tweet composition view controller modally.
        [delegate presentModalViewController:tweetViewController animated:YES];
        //tweetViewController.view.hidden = YES;
        for (UIView *view in tweetViewController.view.subviews){
            [view removeFromSuperview];
        }

     } 

here , deleate is your viewcontroller , if you are using this method inside your viewcontroller just use self instead of delegate.

like image 89
PJR Avatar answered Oct 21 '22 06:10

PJR


iOS 6 uses SLComposeViewController instead of TWTweetComposeViewController, so now you have to do this if you want it to work on iOS 6 and iOS 5:

    UIViewController *tweetComposer;

    if([SLComposeViewController class] != nil)
    {
        tweetComposer = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

        [(SLComposeViewController *)tweetComposer setCompletionHandler:^(SLComposeViewControllerResult result)
         {
            // do whatever you want
         }];
    }
    else
    {
        tweetComposer = [[TWTweetComposeViewController alloc] init];

        [(TWTweetComposeViewController *)tweetComposer setCompletionHandler:^(TWTweetComposeViewControllerResult result)
         {
            // do whatever you want
         }];
    }

    for (UIView *view in [[tweetComposer view] subviews])
        [view removeFromSuperview];

    [self presentViewController:tweetComposer animated:NO completion:nil];
like image 44
Senior Avatar answered Oct 21 '22 06:10

Senior