[英]Objective-C Facebook login with SDK 4.0.1
I just upgraded my objective-C code to the newest Facebook SDK 4.0.1 and I can't really understand what am I missing in my login sequence. 我刚刚将我的Objective-C代码升级到最新的Facebook SDK 4.0.1,我无法理解登录序列中缺少的内容。 I followed exactly the guide and the login does work for me but my only problem is that I'm not sure how can I react to the login.
我完全按照指南进行操作,登录对我有用,但我唯一的问题是我不确定如何对登录做出反应。
So what I'm trying to do is that as soon as the Facebook login succeeded I would like to fetch his details, now for some reason I can't find out how to do it. 所以我想要做的是,一旦Facebook登录成功,我想获取他的详细信息,现在由于某种原因我无法找到如何做到这一点。
I read that I should put the following code in my viewDidLoad: 我读到我应该将以下代码放在我的viewDidLoad中:
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
}
}];
}
But this code is never being executed when the Facebook login finishes successfully. 但是,当Facebook登录成功完成时,此代码永远不会被执行。
When I used to work with the FBLoginView I used the below code in order to get the user details: 当我以前使用FBLoginView时,我使用下面的代码来获取用户的详细信息:
- (void)loginViewFetchedUserInfo:(FBSDKLoginManager *)loginView
user:(FBSDKProfile*)user {
NSLog(@"User Details");}
Is there any equivalent function that I can use with the new SDK ? 我可以使用新SDK的等效功能吗?
Thanks for helping ! 谢谢你的帮助!
Edit : 编辑:
I rezlied I can use the function : 我rezlied我可以使用该功能:
- (void) loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
error:(NSError *)error{
NSLog(@"LOGGED IN TO FACEBOOK");
}
But I think I should also add a delegate to my controller and I'm not sure how.. any help on this one? 但我想我也应该给我的控制器添加一个代表,我不知道怎么...这个有什么帮助? Am I in the right direction?
我是朝着正确的方向吗?
Thanks again ! 再次感谢 !
Make a custom method and get result into that 制作一个自定义方法并将结果输入其中
-(void)fetchUserInfo {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
}
}];
}
You can call that function if login is successful. 如果登录成功,您可以调用该功能。
- (void) loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
error:(NSError *)error{
NSLog(@"LOGGED IN TO FACEBOOK");
[self fetchUserInfo];
}
and in you viewDidLoad method 并在你viewDidLoad方法
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib
if ([FBSDKAccessToken currentAccessToken]) {
NSLog(@"Token is available");
[self fetchUserInfo];
} else {
FBSDKLoginButton *loginView = [[FBSDKLoginButton alloc] init];
loginView.readPermissions = @[@"email"];
loginView.frame = CGRectMake(100, 150, 100, 40);
loginView.delegate = self;
[self.view addSubview:loginView];
}
}
At the end the solution was in here: Facebook iOS8 SDK build module error for FBSDKCoreKit 最后解决方案就在这里: FBSDKCoreKit的Facebook iOS8 SDK构建模块错误
Thanks everyone for your help ! 谢谢大家的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.