How to clear the cookies for foursquare in iphone application? - iphone

I am using foursquare in my application but I can't to sign-out from the foursquare in my application.

Use below code to remove foursquare cookie from app
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"foursquare"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}

You need to call this wherever you want to just like
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie* cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
if ([cookie.name isEqualToString:#"FourSquare"]) {//its temprory name for your understanding
[cookies deleteCookie:cookie];
};
}

Related

Refresh UITableView not working

In the view controller there is a UITableView, in last section last row, there is a Facebook sign in and sign out button as toggle. If user signed in it automatically turn to sign out and vice versa. The problem is when signing in control goes out of app in safari then comes back and view automatically refreshes, but when signing out UITableView doesn't reload. Below is code i'm using.
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];
isFb = 0;
[tableView_detailsEdit reloadData];
[[FBSession activeSession] closeAndClearTokenInformation];
}
}
isFb = 0;
[[FBSession activeSession] closeAndClearTokenInformation];
[tableView_detailsEdit reloadData];
Problem is UITableView delegate methods not getting called. Thus, text on cell in table view doesn't gets change after sign out to sign in.
Please guide for above.
Use following
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
[tableView_detailsEdit reloadData];
}];
Or
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[tableView_detailsEdit reloadData];
});

How can logout foursquare in iphone integration?

How the foursquare Logout functionality has to be implemented in iPhone integration application?
I tried this code.But it is not working.
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString *domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"https://foursquare.com/"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}

How to maintain and clear sessions in a UIwebview?

How to maintain and clear sessions in a UIwebview in iphone sdk
Just delete the cookies from the application. I used this for FBGraph as I was unable to logout from Facebook. You can use this.
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#“yourDomainName"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}

iPhone: Facebook logout feature does not working

I am implementing Facebook integration using FBConnct and it works fine but when I
want to log out from the Facebook it doesn't work.
My code is as follows:
- (IBAction)logOutbuttonPressed:(id)sender {
[Facebook logout:self];
}
- (void)fbDidLogout {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:#"FBAccessTokenKey"];
[defaults removeObjectForKey:#"FBExpirationDateKey"];
NSLog(#" after %#",facebook.accessToken);
NSLog(#" date%#",facebook.expirationDate);
[defaults synchronize];
}
- (void)logout:(id<FBSessionDelegate>)delegate {
[self logout];
if (delegate != self.sessionDelegate &&
[delegate respondsToSelector:#selector(fbDidLogout)]) {
[delegate fbDidLogout];
}
+(void)fbDidLogout
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:#"FBAccessTokenKey"])
{
[defaults removeObjectForKey:#"FBAccessTokenKey"];
[defaults removeObjectForKey:#"FBExpirationDateKey"];
[defaults synchronize];
}
// Hide the publish button.
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];
}
}
}
You need to implement this code for facebook logout as well
- (void)fbDidLogout {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:#"FBAccessTokenKey"];
[defaults removeObjectForKey:#"FBExpirationDateKey"];
NSLog(#" after %#",facebook.accessToken);
NSLog(#" date%#",facebook.expirationDate);
[defaults synchronize];
// Finding the Facebook Cookies and deleting them
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:
[NSURL URLWithString:#"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
fbGraph = nil;
}
Try this
import 'FBConnect.h'
in ur second view controller
then .......
FBSession *session = [FBSession session]; [session logout];
Call this method to logout from facebook.
- (void)logOutFB {
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];
}
}
}

Facebook Connect iPhone API logout not working

I am attempting to write a Facebook integration in an iPhone app I'm working on. I have it logging in just fine, but I don't like the idea of being able to turn a feature on without being able to turn it off. So, in working on the logout functionality, I have been caught in a snag.
- (IBAction) logoutClicked:(id)sender {
if (fbLoggedIn)
{
FBSession * mySession = [FBSession session];
[mySession logout];
}
}
- (void)sessionDidLogout:(FBSession*)session
{
NSLog(#"Session logged out.");
[theLoginButton setTitle:#"Facebook Time!" forState:UIControlStateNormal];
fbLoggedIn = FALSE;
theLogoutButton.enabled = NO;
theLogoutButton.alpha = 0;
}
The logoutClicked method responds to a button in my xib. The delegate method is not getting called. I have tried setting the Facebook session as a property in my ViewController in order to store/access the data across methods, but that didn't seem to work either. Anybody have any solutions?
Is the sessionDidLogout implemented in a class which implements FBSessionDelegate?
And is it an instance of that class that you passed as a delegate when creating the session with the method [FBSession sessionForApplication:#"XXX" secret:#"YYY" delegate:(DELEGATE)] ?
This works for me:
(void)logout {
//self.sessionDelegate = delegate;
appDelegate.facebook.accessToken = nil;
appDelegate.facebook.expirationDate = nil;
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:#"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
NSLog(#"Log out");
// Remove saved authorization information if it exists
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if ([userDefaults objectForKey:#"FBAccessTokenKey"]) {
[userDefaults removeObjectForKey:#"FBAccessTokenKey"];
[userDefaults removeObjectForKey:#"FBExpirationDateKey"];
[userDefaults synchronize];
}
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];
}
}
}
Put this code for logout. I got this from this link.
- (void) fbDidLogout {
NSLog(#"Log out");
// Remove saved authorization information if it exists
if ([userDefaults objectForKey:#"FBAccessTokenKey"]) {
[userDefaults removeObjectForKey:#"FBAccessTokenKey"];
[userDefaults removeObjectForKey:#"FBExpirationDateKey"];
[userDefaults synchronize];
}
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];
}
}
}