Error logging in using facebook iOS sdk

We got into the problem of logging into iOS facebook. When I log into facebook using my application, it asks for user permission using the "login" and "cancel" buttons. But this screen appears only for the first time. those. As soon as we logged in using a safari or application, and even if we left the facebook application, the application requesting user permission displays only the "ok" button. It does not allow logging in as another user. Why is the screen with the "login" and "cancel" buttons not displayed every time the application starts? I tried to delete cookies and delete NSUserDefaults, but with no luck.

The problem after logging out, I can not log in to facebook as another user. It is still displayed as the same user.

I call the following logout function in sdk

(void)logout:(id<FBSessionDelegate>)delegate { self.sessionDelegate = delegate; [_accessToken release]; _accessToken = nil; [_expirationDate release]; _expirationDate = nil; NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSArray* facebookCookies = [cookies cookiesForURL: [NSURL URLWithString:@"http://login.facebook.com"]]; for (NSHTTPCookie* cookie in facebookCookies) { [cookies deleteCookie:cookie]; } if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogout)]) { [_sessionDelegate fbDidLogout]; } } 

Also in the fbDidLogout delegate function, I deleted all NSUserDefaults objects

 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults objectForKey:@"FBAccessTokenKey"]) { [defaults removeObjectForKey:@"FBAccessTokenKey"]; [defaults removeObjectForKey:@"FBExpirationDateKey"]; [defaults synchronize]; } 

regrds shihab

+6
source share
5 answers

FBSession openWithBehavior: completeHandler: can be used ..

 FBSession *fbSession = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObjects:@"email",@"publish_actions",@"publish_stream", nil]]; [fbSession openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session,FBSessionState state, NSError *error){ [FBSession setActiveSession:fbSession]; // Retain the Active Session. }]; 

To exit Ans, Ellen S .. did a great job with iOS.

+4
source

You can clear the session as well as clear the cookies with the following code:

 FBSession* session = [FBSession activeSession]; [session closeAndClearTokenInformation]; [session close]; [FBSession setActiveSession:nil]; NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"https://facebook.com/"]]; for (NSHTTPCookie* cookie in facebookCookies) { [cookies deleteCookie:cookie]; } 
+7
source

I modified the fbDidLogout method and it worked, here is the code:

 -(void) fbDidLogout { NSLog(@"Logged out of facebook"); NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (cookie in [storage cookies]) { NSString* domainName = [cookie domain]; NSRange domainRange = [domainName rangeOfString:@"facebook"]; if(domainRange.length > 0) { [storage deleteCookie:cookie]; } } }//End of Method 

The method successfully displays the user. Hope this helps!

+5
source

I just realized that I got the iPhone settings and got privacy by selecting the Facebook tab and disconnected where it says that the applications that requested access to your Facebook account will appear here. It is working!!!

+2
source

When you log in to enter loginBehavior, when you exit it, with a different login name, only the authorized one will not be displayed, without the login screen login.loginBehavior = FBSDKLoginBehaviorWeb; I use facebook 4.11, it works

0
source

Source: https://habr.com/ru/post/907470/


All Articles