gpt4 book ai didi

ios - 在 ios 中使用 Facebook SDK 的注销功能

转载 作者:行者123 更新时间:2023-12-01 17:55:30 25 4
gpt4 key购买 nike

我已经使用 Facebook SDK 注销了 facebook。但是,再次转到同一帐户,它在表格 View 中显示值两次(例如:Prem Kumar。此名称在单元格中显示两次)。

//用于登录

- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView

{
// first get the buttons set for login mode


NSLog(@"success");


[HUD showWhileExecuting:@selector(LoadingProcess) onTarget:self withObject:nil animated:YES];

if (FBSession.activeSession.isOpen)
{

NSLog(@"TOKEN : %@",[[FBSession activeSession]accessTokenData]);

FBRequest *friendRequest = [FBRequest requestForGraphPath:@"me/friends?fields=name,picture,birthday,location"];

[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSArray *data = [result objectForKey:@"data"];
for (FBGraphObject<FBGraphUser> *friend in data)
{
[delegate.friendsListArray addObject:friend];
NSLog(@"%@:%@:%@", [friend name],[friend birthday],[friend id]);
}

if ([delegate.friendsListArray count]!=0)

{


NSUserDefaults * standardDefaults=[NSUserDefaults standardUserDefaults];
[[NSUserDefaults standardUserDefaults] synchronize];

[standardDefaults setObject:delegate.friendsListArray forKey:@"FriendsListArray"];
[standardDefaults setBool:YES forKey:@"logged_in"];
[standardDefaults synchronize];


NSLog(@"%@",[standardDefaults objectForKey:@"FriendsListArray"]);

BirthdayList * birthdaylist=[[BirthdayList alloc]init];
[self.navigationController pushViewController:birthdaylist animated:NO];
[birthdaylist release];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Friends not found" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}];

}

}

在设置.m
-(void)LogoutTapped
{


NSLog(@"Logged out of facebook");

NSUserDefaults * standardDefaults=[NSUserDefaults standardUserDefaults];
[[NSUserDefaults standardUserDefaults] synchronize];

NSArray *keys = [[[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]allKeys]copy];

for(NSString *key in keys)
{
[standardDefaults removeObjectForKey:key];
[standardDefaults removeObjectForKey:@"FriendsListArray"];
[standardDefaults removeObjectForKey:@"logged_in"];
[standardDefaults synchronize];

NSLog(@"Key Name: %@", key);

}

[delegate.friendsListArray removeAllObjects];
[keys release];

NSLog(@"%@",[standardDefaults objectForKey:@"FriendsListArray"]);

NSLog(@"%@",[standardDefaults objectForKey:@"logged_in"]);


NSUserDefaults * userinfodefaults=[NSUserDefaults standardUserDefaults];
NSArray *userkeys = [[[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]allKeys]copy];

for(NSString *userkey in userkeys)
{
[userinfodefaults removeObjectForKey:userkey];
[userinfodefaults removeObjectForKey:@"userinfo"];
[userinfodefaults removeObjectForKey:@"userbool"];

NSLog(@"key1 Name: %@",userkey);
}

[delegate.UserListArray removeAllObjects];
[delegate.Setmonthdataarray removeAllObjects];
[delegate.SetMonthlistarray removeAllObjects];
[userinfodefaults synchronize];
[userkeys release];


FBSession *session=[FBSession activeSession];
[session closeAndClearTokenInformation];
[session close];
[[FBSession activeSession] closeAndClearTokenInformation];
[[FBSession activeSession] close];
[FBSession setActiveSession:nil];

[delegate facebook].accessToken=nil;
[delegate 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];
}

for (NSHTTPCookie *_cookie in cookies.cookies)
{
NSRange domainRange = [[_cookie domain] rangeOfString:@"facebook"];
if(domainRange.length > 0){
[cookies deleteCookie:_cookie];
}
}


UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Logout" message:@"Logout Successfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

MainList * mainlist=[[MainList alloc]initWithNibName:@"MainList" bundle:nil];

[self.navigationController pushViewController:mainlist animated:NO];

[mainlist release];

}

还有一个疑问。

要登录 facebook,我使用了 Facebook SDK。

要注销 facebook,我使用了 Facebook 库。(Facebook.m,Facebook.h)

有什么问题吗?

任何想法请帮助我。

最佳答案

以下代码可能对您有所帮助:

-(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];
}
}
}//

根据您的上下文,我假设您的设备没有安装 Facebook 应用程序,您也不希望使用 iOS 6 系统身份验证,这将保留默认登录行为以使用 Safari。如果您要清除 Safari cookie,那应该可以,但为了在您的场景中获得更流畅的体验,您应该使用 FBSession openWithBehavior:completionHandler:方法并指定 FBSessionLoginBehaviorForcingWebview 的行为以便它使用内联 webview 对话框进行身份验证。

有关示例,请参阅 Facebook iOS SDK 中的 SwitchUserSample,因为该示例演示了一个可以在多个帐户之间切换的应用程序。

https://developers.facebook.com/docs/ios/login/#logout

https://developers.facebook.com/docs/ios/ios-sdk-tutorial/

关于ios - 在 ios 中使用 Facebook SDK 的注销功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18502152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com