ios - xcode 6: TwitterKit not keeping session open after Authentication -
i'm calling session in loginviewcontroller seen below. problem that, after authenticates , closes popupview... session returns nil. reaches out api , starts session (the first log records nil session open , second log records "signed in as..." username) when closes login view records nil again. not use doing wrong...
could because i'm using twtrsession* session check session? logging me off? or related me closing popupview?
i same thing facebook login facebook session stays open until logout...
- (void)viewdidload { [super viewdidload]; self.email.delegate = self; self.pass.delegate = self; //self.view.frame = cgrectmake(self.bounds.size.width, self.bounds.size.height); [fabric with:@[[twitter sharedinstance]]]; twtrsession* session; if (session) { nslog(@"early bird %@", [session username]); [self closepopup]; } else { nslog(@"no dice"); } /* twtrloginbutton *loginbutton = [twtrloginbutton buttonwithlogincompletion:^(twtrsession *session, nserror *error) { // play twitter session }]; loginbutton.center = self.view.center; [self.view addsubview:loginbutton]; */ twtrloginbutton* loginbutton = [twtrloginbutton buttonwithlogincompletion: ^(twtrsession* session, nserror* error) { if (session) { nslog(@"signed in %@", [session username]); [self closepopup]; } else { nslog(@"error: %@", [error localizeddescription]); } }];
i decided include actionsheet see how i'm handling login/logout situation:
- (void)sheet: (id) sender { nsstring *email = [[nsuserdefaults standarduserdefaults] objectforkey:@"email"]; uiactionsheet *sheet; twtrsession *session; //if ([fbsdkaccesstoken currentaccesstoken]) { if (email == nil && [fbsdkaccesstoken currentaccesstoken] == nil && session == nil) { sheet = [[uiactionsheet alloc] initwithtitle:@"profile" delegate:nil // can value overridden when showing handler. cancelbuttontitle:@"cancel" destructivebuttontitle:@"login" otherbuttontitles:nil]; } else { sheet = [[uiactionsheet alloc] initwithtitle:@"profile" delegate:nil // can value overridden when showing handler. cancelbuttontitle:@"cancel" destructivebuttontitle:@"logout" otherbuttontitles:@"user page", nil]; } [sheet showinview:self.view handler:^(uiactionsheet *actionsheet, nsinteger buttonindex) { if (buttonindex == [actionsheet cancelbuttonindex]) { nslog(@"cancel button index tapped"); } else if (buttonindex == [actionsheet destructivebuttonindex]) { if (email == nil && [fbsdkaccesstoken currentaccesstoken] == nil && session == nil) { loginviewcontroller *loginview = [[loginviewcontroller alloc] initwithnibname:@"loginview" bundle:[nsbundle mainbundle]]; //[self.view modalviewcontroller:loginview animated:yes]; //[self presentmodalviewcontroller:loginview animated:yes]; //[self.navigationcontroller pushviewcontroller:loginview animated:yes]; loginview.delegate = (id) self; [self presentpopupviewcontroller:loginview animationtype:mjpopupviewanimationslidetopbottom]; nslog(@"login view"); } else { [[nsuserdefaults standarduserdefaults] setobject:nil forkey:@"email"]; fbsdkloginmanager *logout = [[fbsdkloginmanager alloc] init]; [logout logout]; } } else { nslog(@"button %i tapped", buttonindex); if (buttonindex == 1) { userviewcontroller * userview = [[userviewcontroller alloc] initwithnibname:@"userview" bundle:[nsbundle mainbundle]]; [userview setuemail:email]; [self presentviewcontroller:userview animated:yes completion:nil]; } } }]; }
so ended creating own custom ibaction handle twitter logins. works better. have careful how check if session active:
-(ibaction)twlogin:(id)sender { [fabric with:@[[twitter sharedinstance]]]; [[twitter sharedinstance] loginwithcompletion:^ (twtrsession *session, nserror *error) { if (session) { nslog(@"signed in %@", [session username]); twtrshareemailviewcontroller* shareemailviewcontroller = [[twtrshareemailviewcontroller alloc] initwithcompletion:^(nsstring* email2, nserror* error) { nslog(@"email %@, error: %@", email2, error); }]; [self presentviewcontroller:shareemailviewcontroller animated:yes completion:nil]; [self closepopup]; nslog(@"session check %@", [session username]); } else { nslog(@"error: %@", [error localizeddescription]); } }]; [[twitter sharedinstance] logout]; }
as can see twtr *session has included twitter shared instance so:
[[twitter sharedinstance] loginwithcompletion:^ (twtrsession *session, nserror *error) {
i didn't before, , that's why wasn't working. helps someone. (now if me getting twitter emails work... appreciated...)
Comments
Post a Comment