Disconnecting Facebook from app on iOS6? - ios

I'm using the latest Facebook iOS SDK, 3.1.1. I want to give users the option to "disconnect" our app from Facebook. I'm calling:
[[FBSession activeSession] closeAndClearTokenInformation];
That seems to work fine, but the next time I call
[FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler:handler];
it immediately gives me a token, without asking the user to login again. I would expect it to ask the user again to authenticate. If there's no Facebook account set up on the device, it works fine, because it opens the web browser where it tells the user they've already authenticated the app and shows the 'Okay' button. But if it is set up, it just silently gets the token again and so the user's "disconnecting" the app has no effect.
Is anyone else having this issue, and how are you handling it?

It doesn't ask again because the iOS SDK has given the Facebook SDK a valid access token. This is just how Apple designed their Facebook (and Twitter) frameworks. There's nothing you can do about it. Personally I think it's great. The user should only have to tell their phone once that they accept an app.
Also note that the cached token may have expired. The Facebook SDK at present doesn't fully handle the case where the iOS SDK gives it an expired token.
If you want to test then you can delete the Facebook account on your device and re-add it. That should clear the cached token.

Using:
- (void)openWithBehavior:(FBSessionLoginBehavior)behavior completionHandler:(FBSessionStateHandler)handler;
with FBSessionLoginBehaviorForcingWebView as the behaviour solved my problem. It opens the login modal box and forgets the user cookies.

Related

How to know user has already done Facebook login at iOS app

I am developing iOS App which use Facebook iOS SDK 4.
When user has already done Facebook login, by doing Facebook login the dialog which shows "user has already approved your app" had be displayed.
So, do not show the dialog. I want to know whether the user has already done Facebook login.
Anyone know the good way? I think accessToken is returned if user once had done Facebook login.
FBSDKAccessToken manage current logged user's accessToken.
According to official Facebook Login guide
"FBSDKAccessToken Represents the access token provided by a successful login. Most important, it provides a global +currentAccessToken to represent the currently logged in user."
The currentAccessToken is a convenient representation of the token of the current user and is used by other SDK components (like FBSDKLoginManager).
According to above you can check either user has valid accessToken or not and based on this you can track call login method otherwise just skip to next flow.
In Facebook the access tokens are per user so you can pass them around apps and they will work. In your case if you can ship an access token from another app you will be able to skip the next logging in and use the API normally.
However I think this this thread will help you.
Things are a little bit different with iOS cause I have done a facebook login on Android and got no such issues.

Facebook Login with another account from iOS app

I'm developing an iOS app that integrates with Facebook SDK. When I make the login for the first time with my facebook account it takes the following steps:
Jump to safari web login
Insert my credentials
After that I authorize the permissions that are requested
And then I go to the main menu of my application.
When I press the logout button, I run the following code:
- (void)logout {
[FBSession.activeSession closeAndClearTokenInformation];
}
With this code I can invalidate the session and clear the access token information. However, when i try to login again, my application jumps to safari web login and my account appears already as logged in (next picture).
If I want to login with another Facebook account, i can't do it. In other words, I would like to follow the steps that I said earlier or have a mechanism like "Not you?" that Facebook official app provides.
Any idea that what I have to do?
You're still logged in through Safari. Log out there (or clear your cache).
wrong, happens when not logged in safari and FB app.

Permissions dialog in Facebook iOS native app

I'm using Facebook iOS SDK 3.5 to log-in into my app, the following method is invoked:
FBSession openActiveSessionWithReadPermissions
If native iOS login is not enabled and facebook iOS app is installed, the login process will get redirected to the facebook app. The problem is that every single time 'FBSession openActiveSessionWithReadPermissions'is invoked, the facebook app presents the permission dialog to the user, even when the user already authorized the FB app.
The permission list is empty (nil). This problem does not happen if native ios or safari are used to log -in.
Any ideas? Thanks
You can check if the user has successfully logged in by checking for an access token here
Also, you can make sure you aren't popping up a GUI from each call by setting allowLoginUI to false.
+ (BOOL)openActiveSessionWithAllowLoginUI:(BOOL)allowLoginUI;
I've not done any iOS FB stuff myself, but that's what I got from reading the docs.
Also, there seems to be a somewhat related question posted here.

Facebook iOS SDK and Safari based authentication issue

I have used latest FB SKD in my iOS app so users can use facebook account to login. Application open the FB app and comes back to my app perfectly fine. However, in some place in the app, i have to show/pull some people facebook page (safari based using WebView), but even user already used the Facebook account to login into my native ios app, but the page still ask user to login again and when they click login, it shows them the annoying FB username/pass page.
Is there anyway, that the FB safari based page can authenticate the user since it's already logged into my app using FB integration? do i have to include query or something. Please give me details how to solve this problem since i'm new in this..
thanks again for your help...
pic: https://www.dropbox.com/s/rjlptu7ufpcq3vl/fb.png
When the user switches to Facebook app to authenticate, it doesn't create a cookie for your UIWebView which is why it's asking to login again. Have the user authenticate inside the UIWebView without switching to the Facebook app.
What you're talking about also sounds like a similar thing that happens with Facebook dialogs not knowing about the current Facebook session.
If you authenticate your user via Facebook, try saying the Facebook object itself as an instance variable somewhere in memory so you can access it again (a property on a singleton controller, perhaps?).
Spawning dialogs from an authenticated Facebook object appears to let them use the dialog without reauthenticating iff you have a [FBSession activeSession]. So you'd also have to maintain an active FB session. But I'm not sure if this kind of solution will work since you didn't show specific code for how you're doing your web-based FB fetches.
This question might also prove helpful:
Implement Login with Facebook in iOS 5 and 6

can't switch users for FB connect on iOS

I have FB connect implemented in my app. After battling with the FB app installed on a user's phone, I finally had success forcing the standard FB dialog and bypassing the FB app
(see iOS: Connect to Facebook without leaving the app for authorization)
My new problem is that I cannot seem to switch FB users within the app. When I click the "Login with Facebook" button from within my app, it quickly brings up the FB dialog, dissappears, and always logs me back in with the previous user (meaning I have no way to switch FB users).
I've check both Safari and the FB app, and neither are logged in. Do I have to tell FB to log out the previous user before a new user/pass is prompted?
Thanks
Your implementation probably saves user's access token in NSUserDefaults. If it is so - you just need to delete it from NSUserDefaults any time there is a logout or you're switching users.
Also if needed you are able to deauthorize the user by making a DELETE graph API call to uid/permissions.
hope this helps

Resources