Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:12:41+00:00 2026-05-29T11:12:41+00:00

I am integrating twitter in my app for sharing a text. My architecture of

  • 0

I am integrating twitter in my app for sharing a text. My architecture of twitter integration is I have two Button _btnTwitter and _btntwitteLogout and when the user successfully login the twitter his name will display in _btntwitterLogout as title.

When the user tap the _btntwitterLogout it logs out the twitter and logout button hides and login button comes.every thing went ok.but when the user tap the login button(_btnTwitter) the Twitter login popup cmes for login purpose,here is the problem that am facing ,when the popup comes the user tap the cancel button of that popup the popup disappears and here the previous username of the user in the logout button.it didn’t changes. I have put user defaults to check.

-(IBAction)_clickbtnTwitter:(id)sender
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"Twitter_logged"];
       [_btntwitterLogeout setTitle:nil forState:UIControlStateNormal];
        _btntwitterLogeout.hidden = NO;
        _btnTwitter.hidden=YES;
    if (_engine) return;
    _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
    _engine.consumerKey = kOAuthConsumerKey;
    _engine.consumerSecret = kOAuthConsumerSecret;

    UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self];

    if (controller) 
        [self presentModalViewController: controller animated: YES];
    else {
        [_engine sendUpdate: [NSString stringWithFormat: @"Already Updated. %@", [NSDate date]]];

    }
}
}

then logout code

-(IBAction)_clickbtntwitterlogeout:(id)sender
{ 

    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"Twitter_logged"];
    crosstwitterimage.hidden = YES;
     [_btntwitterLogeout setTitle:nil forState:UIControlStateNormal];
   _btntwitterLogeout.hidden = YES;
    _btnTwitter.hidden=NO;
    _btnTwittermain.enabled = NO;
    [_engine clearAccessToken];
    [_engine clearsCookies];
    [_engine setClearsCookies:YES];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"authData"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"authName"];
    NSLog(@"%@",[[NSUserDefaults standardUserDefaults]valueForKey:@"authName"]);
    NSLog(@"%@",[[NSUserDefaults standardUserDefaults]valueForKey:@"authData"]);
   [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"Twitter_logged"];
    [_engine release];
    _engine=nil;   

    NSHTTPCookie *cookie;
    NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (cookie in [storage cookies])
    {
        NSString* domainName = [cookie domain];
        NSRange domainRange = [domainName rangeOfString:@"twitter"];
        if(domainRange.length > 0)
        {
            [storage deleteCookie:cookie];

        }
    }

}

in viewwillappear

BOOL logged = [[NSUserDefaults standardUserDefaults] boolForKey:@"Twitter_logged"];
;
if (logged == YES) {
    _btnTwitter. hidden = YES;
    _btntwitterLogeout.hidden = NO;
    crosstwitterimage.hidden = NO;
    _btnTwittermain.enabled =YES;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    //Checks if there is a saved User Name    
    if([defaults objectForKey:@"kTwitterUserName"])
    {
        NSString *username = [defaults objectForKey:@"kTwitterUserName"];
        [_btntwitterLogeout setTitle:username forState:UIControlStateNormal];
        crosstwitterimage.hidden = NO;
    }
}
    else
    {
        _btnTwitter. hidden = NO;
        crosstwitterimage.hidden = YES;
        [_btntwitterLogeout setTitle:nil forState:UIControlStateNormal];
        _btnTwittermain.enabled =NO;
        crosstwitterimage.hidden = YES;

    }

but when i tap the cancel button in loginwindow of twitter,an comes back the username with the logout button shows ,if the user is already logedout from twitter.
is there any problem in my code.
thanks in advance.

EDIT

#pragma mark SA_OAuthTwitterEngineDelegate
- (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username {
    NSUserDefaults          *defaults = [NSUserDefaults standardUserDefaults];

    [defaults setObject: data forKey: @"authData"];
    [defaults synchronize];
}

- (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username {
    return [[NSUserDefaults standardUserDefaults] objectForKey: @"authData"];
}

    #pragma mark SA_OAuthTwitterControllerDelegate
    - (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
        NSLog(@"Authenicated for %@", username);
        [_btntwitterLogeout setTitle:username forState:UIControlStateNormal];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:username forKey:@"kTwitterUserName"];
        [defaults synchronize];
        }

    - (void) OAuthTwitterControllerFailed: (SA_OAuthTwitterController *) controller {
        NSLog(@"Authentication Failed!");
    }

    - (void) OAuthTwitterControllerCanceled: (SA_OAuthTwitterController *) controller {
        NSLog(@"Authentication Canceled.");
    }


    #pragma mark TwitterEngineDelegate
    - (void) requestSucceeded: (NSString *) requestIdentifier {
        NSLog(@"Request %@ succeeded", requestIdentifier);
    }

    - (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error {
        NSLog(@"Request %@ failed with error: %@", requestIdentifier, error);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:12:42+00:00Added an answer on May 29, 2026 at 11:12 am

    Yes there is a problem. Whenever you hit the _btnTwitter, you are setting the Twitter_logged to yes. That’s not correct. You should only set it to yes when there is a successful login. That is when the user has NOT hit cancel on the twitter login window.

    In other words, you need to set the Twitter_logged to YES once the user has actually logged in, not when the user clicked on the button _btnTwitter

    Seems like SA_OAuthTwitterController has a delegate property pointing to self. You should handle code to set Twitter_logged YES in that delegate method.

    Hope that helps.

    Edit:

    Given the latest code here is where you should add the NsUserDefaults data

      - (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
        NSLog(@"Authenicated for %@", username);
        [_btntwitterLogeout setTitle:username forState:UIControlStateNormal];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:username forKey:@"kTwitterUserName"];
        [defaults setBool:YES forKey:@"Twitter_logged"]; // Right here - mbh
        [defaults synchronize];
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a rails app with both facebook and twitter integration, everything was
I have Facebook and Twitter integration in my app. For Facebook I use the
I'm integrating my web app with Twitter/Facebook and I have a couple of situations
I'm trying to add Twitter integration to my iOS 6 iPhone app. I have
I am currently working on app which is supposed to have Twitter integration. The
My client wants twitter integration in my iPhone app in this way that User
I have an app with a login screen with a button that invites users
I made a twitter integration to my android app. I used this great tutorial,
I originally used this tutorial - http://icodeblog.com/2009/07/09/integrating-twitter-into-your-applications/ to put twitter into my app. It
i am integrating twitter in my iphone music application.i.e when a user clicks a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.