[[Twitter sharedInstance] sessionStore].session always return nil. why?

ios
oauth
twitterkit

#1

Hi,

I i’m using twitter login in my IOS app. But everytime when i check [[Twitter sharedInstance] sessionStore].session it will return nil. once i login in my app with twitter and then i close the app. after that i restart my app and session response i got is null.

if ([[Twitter sharedInstance] sessionStore].session) {

    NSLog(@"store %@ lastsession %@ session %@ specification %@",store,lastSession,sessions,specificSession);
    
}

I also check this way.
TWTRSessionStore *store = [[Twitter sharedInstance] sessionStore];
TWTRSession *lastSession = store.session;
NSArray *sessions = [store existingUserSessions];

what i’m trying to do is if the session exist then user will redirect to Home screen else it will redirect to login screen.

the way i’m doing login is below :

  • (IBAction)loginWithTwitterAction:(id)sender {

    [[Twitter sharedInstance]logInWithMethods:TWTRLoginMethodWebBased completion:^(TWTRSession * _Nullable session, NSError * _Nullable error) {

    }];

    [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession * _Nullable session, NSError * _Nullable error) {
    if ( session )
    {
    NSString *message = [NSString stringWithFormat:@"@%@ logged in! (%@)",
    [session userName], [session userID]];

          NSLog(@"logIn successfull %@",message);
          
       
         
          
          [self getUserInformation:[session userID]];
          
       
          
      }
      else
      {
          NSLog(@"%@",error);
      }
    

    }];

}

-(void)getUserInformation :(NSString *)userId
{

/* Get user info */


TWTRAPIClient *client = [[TWTRAPIClient alloc] init];
[client loadUserWithID:userId completion:^(TWTRUser *user, NSError *error) {
    if (![error isEqual:nil]) {
        
        NSLog(@"Twitter info   -> user = %@ ",user);
        NSString *urlString = [[NSString alloc]initWithString:user.profileImageLargeURL];
        NSURL *url = [[NSURL alloc]initWithString:urlString];
        NSData *pullTwitterPP = [[NSData alloc]initWithContentsOfURL:url];
        
        UIImage *profImage = [UIImage imageWithData:pullTwitterPP];
        
        
        TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];
        
        NSURLRequest *request = [client URLRequestWithMethod:@"GET"
                                                         URL:@"https://api.twitter.com/1.1/account/verify_credentials.json"
                                                  parameters:@{@"testing9693@gmail.com": @"true", @"skip_status": @"true"}
                                                       error:nil];
        
        [client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            NSLog(@"tMail%@",response);
            
            HomeVC *home=[[HomeVC alloc]initWithNibName:@"HomeVC" bundle:nil];
            [self.navigationController pushViewController:home animated:YES];
        }];

        
    } else {
        NSLog(@"Twitter error getting profile : %@", [error localizedDescription]);
    }


}];

}