Unable to log in as another user after exiting iOS app

So here is my problem. I enter the application and then exit my application, but when I try to log in, I get the screen from the link below.

Login screen

As you can see, I have no way to log in with another user, which was intended.

What I was trying to do was logout and then clear all cookies on logout using the following methods:

@IBAction func logout(sender: AnyObject) { //Logged out here let loginManager = FBSDKLoginManager() loginManager.logOut() //This is one method I tried let appDomain = NSBundle.mainBundle().bundleIdentifier! NSUserDefaults.standardUserDefaults().removePersistentDomainForName(appDomain) //This is another method I tried for key in NSUserDefaults.standardUserDefaults().dictionaryRepresentation().keys { NSUserDefaults.standardUserDefaults().removeObjectForKey(key) } //And this is the last method I tried var cookie: NSHTTPCookie var storage: NSHTTPCookieStorage = NSHTTPCookieStorage.sharedHTTPCookieStorage() for cookie in storage.cookies! { var domainName: String = cookie.domain var domainRange: Range = domainName.rangeOfString("facebook") if domainRange.length > 0 { storage.deleteCookie(cookie) } } } 

None of them seemed to solve my problem. The application is in the "Development" mode in the Facebook Dev account, so it may have something to do with it, but not exactly. Does anyone have experience with this and know the solution to our problem, as shown in the image above.

+5
source share
2 answers

The whole purpose of logging into Facebook is to allow a quick and easy login to your Facebook account without re-entering your credentials.

To achieve this, the Facebook SDK is trying to use credentials that are already stored on the device, which may include:

  • Facebook login information.
  • cookies associated with logging into Facebook in Safari (directly or through SFSafariViewController )
  • Facebook system accounts

When you log out, you only have the SDK for Facebook, which forget the credentials in the application (it clears the token). When you log in again, it acts like the first time you did this, and if it finds an existing user, it will use it (the Facebook SDK makes it generally valid, the assumption that there is one person using device and they have one Facebook account).

The current β€œfavorite” path for the Facebook SDK (although it depends on the SDK versions, iOS versions, and possibly other parameters) is SFSafariViewController , which uses cookies with Safari, and not with your application.

If you want the user to log out completely on the device, they would have to use the Facebook logout link in Safari (or SFSafariViewController ).

If you want to do this programmatically, you can open the following URL in Safari or SFSafariViewController:

 https://www.facebook.com/logout.php?next=[YourAppURL]&access_token=[ValidAccessToken] 

You will need to use a custom URL scheme to return to your application / exit SFSafariViewController .

+1
source

If you, as a user, want to view the permission request from Facebook again, you must remove the application from the user's profile on Facebook.

Facebook - go to settings

When you are on the settings screen, find your application and press the cross button

Facebook - uninstall application

0
source

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


All Articles