我已经在我的应用中实现了 facebook 登录。
1----> 我能够进行 facebook 登录,但登录后用户能够继续使用我的应用程序,即出现带有三个选项卡项的 tabbarController,同时我需要获取 facebook 用户详细信息(电子邮件、名字,姓氏等)
但我无法检索到详细信息。我不明白我哪里出错了。
在我的 ViewController.m 中:
- (IBAction)performLogin:(id)sender
{
AppAppDelegate *appDelegate = (AppAppDelegate *) [[UIApplication sharedApplication] delegate];
[appDelegate openSessionWithAllowLoginUI:YES];
UITabBarController *tabBarController=[[UITabBarController alloc]init];
SearchViewController *searchViewController=[[SearchViewController alloc]initWithNibName:@"SearchViewController" bundle:nil];
UProfile *uprofile=[[UProfile alloc]initWithNibName:@"UProfile" bundle:nil];
userprofile.title=@"My Profile";
LogOut *logout=[[LogOut alloc]initWithNibName:@"LogOut" bundle:nil];
logout.title=@"Sign out";
tabBarController.viewControllers=[NSArray arrayWithObjects:searchViewController,uprofile,logout, nil];
[self presentModalViewController:tabBarController animated:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sessionStateChanged:)
name:FBSessionStateChangedNotification
object:nil];
}
- (void)sessionStateChanged:(NSNotification*)notification {
if (FBSession.activeSession.isOpen) {
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> user,
NSError *error) {
if (!error) {
NSString *fbUserEmail= @"";
NSLog(@"%@",user);
fbUserEmail=[user objectForKey:@"email"];
AppAppDelegate *appDelegate = (AppAppDelegate *) [[UIApplication sharedApplication] delegate];
appDelegate.fbEmail=fbUserEmail;
}
}
];
}
}
但是这里没有显示 facebook 登录页面,我得到了 tabbarController,我无法检索用户详细信息。
如何先显示 facebook 登录页面,然后显示带有用户详细信息的 tabbarController? 成功登录到 facebook 后,如何使用带有第一个 tabitem(相应 View )选择的 tabbarcontroller 继续我的应用程序?
请帮我解决这个问题......拜托
最佳答案
您需要设置 readPermissions 以获取此方法的电子邮件,方法是将对象“email”的 NSArray
传递给它。默认返回名称等其余信息。
+ (BOOL)openActiveSessionWithReadPermissions:(NSArray*)readPermissions
allowLoginUI:(BOOL)allowLoginUI
completionHandler:(FBSessionStateHandler)handler;
的 Facebook SDK。如果我没记错的话,除非指定的权限是“email”,否则用户字典的电子邮件对象是nil
。修改您的状态更改处理程序可能会请求用户详细信息,例如电子邮件。在 sessionStateChanged:
处理程序中,如果 session 打开,您可以调用一个简单地执行此操作的方法
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (!error) {
NSLog(@"%@", user);
NSLog(@"%@", [user objectForKey:@"email"]);
}
}];
}
关于iphone - 在 ios6 中集成 facebook 登录和获取用户详细信息以及 tabbarcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13889494/