gpt4 book ai didi

iphone - 如何检查是否已经在 ios 中登录 Facebook?

转载 作者:行者123 更新时间:2023-11-28 22:28:04 26 4
gpt4 key购买 nike

我在我的应用程序中使用“Graph Api”进行 Facebook 登录。我成功登录并使用此代码注销

    facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:self.viewController];

我使用下面的代码来登录 facebook

 if (![facebook isSessionValid]) {

[facebook authorize:permissions ];
}

我的问题是我安装了 Facebook 应用程序,并通过 Facebook 应用程序登录。然后我运行我的应用程序,它再次询问登录 Facebook。我如何解决这个问题。它应该作为默认的 FB 应用程序登录凭据。我看到很多应用程序使用这个功能。任何人都知道解决方案

最佳答案

  1. In your AppDelegate.m file

define NSString *const FBSessionStateChangedNotification =
@"com.example:FBSessionStateChangedNotification";
replace com.example with your bundle identifier name

2.- In method
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FBSession setActiveSession:[FBSession new]];
if ([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded)
{
// means u are already logged in
//do ur code
[self openSessionWithAllowLoginUI:NO];
}
else
{ //do ur code
[self openSessionWithAllowLoginUI:YES];
}
}
3. whenenever and wherever this method is called after end of switch case write
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{

[[NSNotificationCenter defaultCenter]
postNotificationName:FBSessionStateChangedNotification
object:session];
}

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI
{
return [FBSession openActiveSessionWithReadPermissions:@"email"
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
{
[self sessionStateChanged:session state:state error:error];
}];
}

Sorry in your appDelegate.h file it should be
extern NSString *const FBSessionStateChangedNotification;

关于iphone - 如何检查是否已经在 ios 中登录 Facebook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18332852/

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