gpt4 book ai didi

facebook-ios-sdk - FBLoginView : login isn't performed

转载 作者:行者123 更新时间:2023-12-04 20:10:48 24 4
gpt4 key购买 nike

我将 FBLoginView 添加到我的 ViewController < FBLoginViewDelegate >:

FBLoginView *loginview = [[FBLoginView alloc] init];    
loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;
[self.view addSubview:loginview];
[loginview sizeToFit];

plist 中所有必要的字段(FacebookAppID、FacebookDisplayName、URL Schemes)都根据教程设置。 facebook app也是按照教程配置的(设置bundle ID,启用facebook登录)。

但是登录仍然没有执行。当我按下“登录”时,我被重定向到使用 facebook 登录的浏览器,但是当它完成时,我没有登录应用程序(loginViewFetchedUserInfo:user: 没有被调用,“登录”没有改变以“注销”)。
可能是什么问题?

最佳答案

在 AppDelegate.m 中实现以下内容后,一切正常(取自官方示例之一):

- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
if (!error) {
// We have a valid session
//NSLog(@"User session found");
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (!error) {
self.loggedInUserID = user.id;
self.loggedInSession = FBSession.activeSession;
}
}];
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}

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

if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}

/*
* Opens a Facebook session and optionally shows the login UX.
*/
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
return [FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}

/*
*
*/
- (void) closeSession {
[FBSession.activeSession closeAndClearTokenInformation];
}

/*
* If we have a valid session at the time of openURL call, we handle
* Facebook transitions by passing the url argument to handleOpenURL
*/
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}

关于facebook-ios-sdk - FBLoginView : login isn't performed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17501099/

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