How to clear token using the facebook-ios-sdk v3.2.1? -


i using sample program learn facebook-ios-sdk, found problem: if logged facebook on device , run sample app, fine, however, when delete facebook account device , run sample app again, can still pass login process , scviewcontroller can still seen (there fast-app-switch facebook app process, need click "okey" button, don't need fill email/password information log facebook).

i checked code , found after account removed device, token in fbsession.activesession.accesstoken still considered valid. there problem? , how can clear token , make log in dialog pop up? have invoked [fbsession.activesession closeandcleartokeninformation] when log out, token should cleared, according facebook sdk document, not case.

the environment use: xcode 4.6.1, ipad 6.1 simulator , facebook-ios-sdk v3.2.1.

updated: paste code here: in scappdelegate.m, added 3 functions, not in sample code in sdk online document:

- (void)showloginview {     uiviewcontroller* topviewcontroller = [self.navigationcontroller topviewcontroller];     uiviewcontroller* modalviewcontroller = [topviewcontroller modalviewcontroller];     // if login screen not displayed, display it. if login screen     // displayed, getting here means login in progress did not     // complete. in case, notify login view can update ui appropriately.     if (![modalviewcontroller iskindofclass:[scloginviewcontroller class]]) {         scloginviewcontroller* loginviewcontroller = [[scloginviewcontroller alloc]                                                       initwithnibname:@"scloginviewcontroller"                                                       bundle:nil];         [topviewcontroller presentmodalviewcontroller:loginviewcontroller animated:no];     } else {         scloginviewcontroller* loginviewcontroller = (scloginviewcontroller*)modalviewcontroller;         [loginviewcontroller loginfailed];     } }  - (void)sessionstatechanged:(fbsession*)session state:(fbsessionstate)state error:(nserror*)error {     switch (state) {         case fbsessionstateopen: {             uiviewcontroller* topviewcontroller = [self.navigationcontroller topviewcontroller];             if ([[topviewcontroller modalviewcontroller]iskindofclass:[scloginviewcontroller class]]) {                 [topviewcontroller dismissmodalviewcontrolleranimated:yes];             }         }             break;         case fbsessionstateclosed:         case fbsessionstateclosedloginfailed:             [self.navigationcontroller poptorootviewcontrolleranimated:no];             [fbsession.activesession closeandcleartokeninformation];             [self showloginview];             break;          default:             break;     }     if (error) {         uialertview* alertview = [[uialertview alloc]initwithtitle:@"error" message:error.localizeddescription delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil];         [alertview show];     } }  - (void)opensession {     [fbsession openactivesessionwithreadpermissions:nil allowloginui:yes completionhandler:^(fbsession* session, fbsessionstate status, nserror* error){         [self sessionstatechanged:session state:status error:error];}]; } 

then in scloginviewcontroller.m, add button, instead of using existing fbloginview object, login job. handler function button follows:

- (ibaction)performlogin:(id)sender {     //[self.spinner startanimating];     scappdelegate* appdelegate = [uiapplication sharedapplication].delegate;     [appdelegate opensession]; } 

then in scviewcontroller.m, add button log out job. handler function button follows:

- (ibaction)logoutbuttonwaspressed:(id)sender {     [fbsession.activesession closeandcleartokeninformation]; } 

other code same in sample code.

apart clearing token, need clear cookie stored in safari when use log facebook.

the following works me facebook sdk 3+ on ios 5.1+:

[fbsession.activesession closeandcleartokeninformation];  nshttpcookiestorage *storage = [nshttpcookiestorage sharedhttpcookiestorage]; for(nshttpcookie *cookie in [storage cookies]) {     nsstring *domainname = [cookie domain];     nsrange domainrange = [domainname rangeofstring:@"facebook"];     if(domainrange.length > 0)     {         [storage deletecookie:cookie];     } } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -