The problem is that Facebook use Safari when logged in, so when I try logout from my app it does keep credentials and cookies of Safari.
In other words, the only way to logout correctly is to open Safari and logout from Facebook.
My question is, is there any work around this way?
FBSDKLoginManager *loginManager = [FBSDKLoginManager new];
[loginManager logOut];
I also tried:
[FBSDKAccessToken setCurrentAccessToken:nil];
[FBSDKProfile setCurrentProfile:nil];
Although they are being called inside the logout method :(
Finally I tried removing cookies
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:
[NSURL URLWithString:#"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
No luck at all!
Related
I have integrate facebook api and i easily login but after logout my app from Facebook when i again login then is shows you have already authorised and come to the app home page.But I want if I logout account then next time again require username and password to use the different user.
I already yes ,status and review option from Facebook developers account to live but yet this problem occurs.
your logout is fine I think you are not clear the current session of facebook, when you click the logout button You have to implement the two methods for logout.
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logOut];
set the currentAccessToken to nil
[FBSDKAccessToken setCurrentAccessToken:nil];
[FBSDKProfile setCurrentProfile:nil];
for loginview
- (void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton {
// do like delete the permission, this means you fully logout from facebook
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me/permissions/"
parameters:nil
HTTPMethod:#"DELETE"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"deleted successfully");
}];
}
the above method clear the current session , when you click the facebook button again it ask the new permission for new user.
if you want to clear the safari cookies also use
Only clears the local FB session information but not the Safari cookies. So, after I log in the user, I clear the Safari cookies:
NSLog(#"Logged out 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];
}
}
if you want to access the multiple user in the same time see sample app name Scrumptious you can get this app from here
The Facebook SDK for iOS come with some sample applications. E.g. FriendPickerSample and SessionLoginSample. In both when I try to login it will remember my previous facebook users. But I don't want that because I want to use it with another facebook user. How do I clear the info Facebook has cached so that login will act the same as the very first time I tried to login on this device with this particular app?
Does facebook cache all its information in the app bundled? And what info does it store and in what files?
You need to remove all the keys stored by facebook once user logs out.
- (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];
}
}
}
[[FBSession activeSession] close];
[[FBSession activeSession] closeAndClearTokenInformation];
I am integrated Instagram in iPhone,At first time login page display on my iPhone and after logout when again login than credentials are not Asking and directly login. i also 'nil' old credentials on logout and i also clear cookie at logout but it not working.when i delete cookie from safari then it work fine. how to solve it programetically.
Logout Button code as below
-(void)doLogout
{
IGAppDelegate* appDelegate = (IGAppDelegate*)[UIApplication sharedApplication].delegate;
[cookies deleteCookie:cookie];
// clear cookie
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* instagramCookies = [cookies cookiesForURL:[NSURL URLWithString:#"https://instagram.com/"]];
NSLog(#"Array is == %#",instagramCookies);
for (NSHTTPCookie* cookie in instagramCookies)
{
[cookies deleteCookie:cookie];
}
// accessToken set nil
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:#"accessToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self.navigationController popViewControllerAnimated:YES];
}
We have to use WebView instead of safari so this problem will be solved.
I have made some changes in crino's sdk in which this problem has been resolved.
You can get code from https://github.com/gouravgupta72/instagramIOSsdk/ here.
We have got sruck in the iOS facebook login logout issue. When I login to facebook using my application it will prompt for user permission with 'login' and 'cancel' button. But this screen appears only on the very first time. ie Once we logged in using safari or the app and even if we logged out from facebook , application the screen prompting for user permission displays only an 'ok' button. It doesnt allow to sign in as a different user. Why the screen with 'login' and 'cancel' button not displaying each time the application launches? I tried by deleting cookies and removing NSUserDefaults but no luck.
The problem is after logout, I am unable to login to the facebook as another user. It still shows as the same user.
I am calling the below 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 fbDidLogout delegate function I removed all NSUserDefaults objects
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:#"FBAccessTokenKey"]) {
[defaults removeObjectForKey:#"FBAccessTokenKey"];
[defaults removeObjectForKey:#"FBExpirationDateKey"];
[defaults synchronize];
}
regrds
Shihab
You can clear the session as well as clearing 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];
}
FBSession openWithBehavior:completionHandler: 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.
}];
For Logging out, Ans by Ellen S.. worked fine for iOS .
I modified 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 logs out the user.
Hope this will help!
I just figure it out I got in the settings of my iPhone and got to privacy chose the Facebook tab and turn off where it says Applications that have requested access to you Facebook account will appear here. It works!!!
When login to set to loginBehavior, so when you exit, with the other account login, won't appear only authorized, without the login screen login.loginBehavior =FBSDKLoginBehaviorWeb; i use facebook 4.11,it's work
I implemented Facebook Graph API in my iPhone App and I successfully post it in a wall. But each time I end my application and come back it stores my credentials (in Safari I guess as a cookie). It asks my permission with my previous credentials. But at this point I want my Facebook API should prompt for a new username and password login for requesting permission. In simple I want to logout of my Facebook when i select a button in my App.
fbGraph.accessToken = nil;
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];
}
}
How did you log in to facebook in the first place? If you are using facebook iOS SDK, you just basically have to call [facebook logout:self];. Otherwise if you're implementing Graph API yourself you just need to clear out your cookies and delete your access token.
when you are call the facebook button at that method last line u wil write this method [facebook logout]
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie* cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies])
{
[cookies deleteCookie:cookie];
}
These codes are enough to implement logout functionality.
Its working perfectly on my app.