How do I remove everything my App has stored about Facebook? - ios

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];

Related

facebook login with multiple users

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

How to logout of twitter using fabric in iOS application

Shared Instance Logout does not work. I know this is a big problem for developers. Does anyone have a solution? Thanks
I ran into this issue about 3 months ago and have just now found a solution to this. Apparently clearing cookies does in fact get rid of Twitter's stored information for previously logged in users. The code below is working for me:
!WARNING! Make sure when you first log in that you Disallow Twitter from accessing your accounts on the device. This causes Twitter to force login the user each time instead of looking straight at your Twitter account saved to your device. Hope this helps!
- (IBAction)twitterLogout:(id)sender {
[[Twitter sharedInstance] logOut];
[self.view insertSubview:_logoutTwitter atIndex:16];
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"Twitter"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
NSURL *url = [NSURL URLWithString:#"https://api.twitter.com"];
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];
for (NSHTTPCookie *cookie in cookies)
{
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}

Logout of Active Twitter Session Using Fabric

I have read through the forums and suggestions about how to logout of Twitter in Xcode for IOS using Fabric, but I can't get the logOut method to call and logout the user from the current session. Here is my current code for the login view controller:
- (IBAction)TESTT:(id)sender {
[[Twitter sharedInstance] logInWithCompletion:^
(TWTRSession *session, NSError *error) {
if (session != nil) {
NSLog(#"signed in as %#", [session userName]);
} else {
NSLog(#"error: %#", [error localizedDescription]);
}
}];
}
- (IBAction)LOGOUT:(id)sender {
[self logOut];
}
- (void)logOut{
[[Twitter sharedInstance] logOut];
}
I have imported and have the login functionality working well from the Fabric tutorial.
I just can't get the button that I made which is using the LOGOUT action to logout the user from the current Twitter session. I have even tried to clear the cookies to see if that could wipe the Twitter session from the memory and reset it - but nothing. If anyone could help me out I would really appreciate it - thanks!
FYI: PLEASE do not suggest only [[Twitter sharedInstance] logOut]; . This method does not do what I am asking by itself. If someone can tell me how to successfully logout using this method along with the rest of the procedure that would be fine.
After a long extensive series of methods, clearing of cookies, data, almost everything you could think of, I discovered it is actually quite simple.
The easiest way to sign out and clear the previous user session is as follows:
Go to settings
Go to your Twitter and Disallow Twitter access to your app (it should appear here)
Go back to the app and call the following method:
- (void)twitterLogout:(id)sender {
NSUserDefaults *twitterSession = [NSUserDefaults standardUserDefaults];
[twitterSession setObject:0 forKey:#"TwitterSession"];
[twitterSession synchronize];
NSLog(#"Twitter session = %#", twitterSession);
[[Twitter sharedInstance] logOut];
[self.view insertSubview:_logoutTwitter atIndex:16];
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"Twitter"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
NSURL *url = [NSURL URLWithString:#"https://api.twitter.com"];
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];
for (NSHTTPCookie *cookie in cookies)
{
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}
There is quite a lot in this method, and to be honest some of it is probably extraneous and not even needed, but anyone who needs this can mess around with what should and shouldn't stay. Either way hopefully this helps people - it certainly helped me!
You can use this simple code for Swift 3:
let store = Twitter.sharedInstance().sessionStore
if let userID = store.session()?.userID {
store.logOutUserID(userID)
}

Login Logout issue with facebook iOS sdk

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

How to implement Logout functionality for Facebook graph API

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.

Resources